this is my continuation to last lesson.
Here learning about for loops
the for loop is very similar to 'C'
for ( var initialize; var condition; var increment){
...
}
ex:
for (var counter = 1; counter < 5; counter++){
console.log(counter);
}
Arrays in javascript can store different types of data at same time
ex:
var mixed = [ 23, "us" , 44];
syntax for array is : var name = [var, var, ..];
** the counting inside a array is started from 0
**we can use .length for both arrays as well as strings
**some strings or texts could be quite long, so put '\' backslash at end of each line to wrap to the next line of editor. Best way to avoid using long line
** .push for elements to push to array
ex: array.push(a[0]); here we are pushing element 1 of 'a' to array
while loop is very similar to 'C'
syntax:
while(condition){
do something
}
we check condition by '===' ex: if ( a === 0) {}
** to make sure loop runs atleast once we use 'do while' loop
to print a bool value, and we use String() function, actually string converts anything to string format
ex: var b = true; console.log(String(b)); output is 'true'
Here learning about for loops
the for loop is very similar to 'C'
for ( var initialize; var condition; var increment){
...
}
ex:
for (var counter = 1; counter < 5; counter++){
console.log(counter);
}
Arrays in javascript can store different types of data at same time
ex:
var mixed = [ 23, "us" , 44];
syntax for array is : var name = [var, var, ..];
** the counting inside a array is started from 0
**we can use .length for both arrays as well as strings
**some strings or texts could be quite long, so put '\' backslash at end of each line to wrap to the next line of editor. Best way to avoid using long line
** .push for elements to push to array
ex: array.push(a[0]); here we are pushing element 1 of 'a' to array
while loop is very similar to 'C'
syntax:
while(condition){
do something
}
we check condition by '===' ex: if ( a === 0) {}
** to make sure loop runs atleast once we use 'do while' loop
to print a bool value, and we use String() function, actually string converts anything to string format
ex: var b = true; console.log(String(b)); output is 'true'