JavaScript Programming Constructs

JavaScript syntax is similar to C language. JS provides below programming constructs.
  • if ... else
  • for loop, for..in loop, for .. of loop
  • while loop and do...while loop
  • switch ... case

let a = [2,3,"hello"]
//prints false
if (a[0] > a[1])
{
    console.log("true")
}else {
    console.log("false")
}


//for loop
//prints 2,3,"hello"
for(i=0;i<a.length;i++){
    console.log(a[i])
}

//for..in - returns props
//prints 0, 1, 2
for(x in a){
    console.log(x)
}

//for..of - returns values
//prints 2,3,"hello"
for(x of a){
    console.log(x)
}

//while
let j = 0
while(j<a.length)
{
    console.log(a[j])
    j++
}

j = 0
do{
    console.log(a[j])
    j++
}while(j<a.length)

Web development and Automation testing

solutions delivered!!