for loop if statement javascript code example
Example 1: javascript loop if statement
for (let i = 0; i < 10000; i++) {
console.log('huduiduin 100000 times');
}
Example 2: using if statements in javascript
if (expression) {
Statement(s) to be executed if expression is true
} else {
Statement(s) to be executed if expression is false
}
Example 3: javascript if statement
if (5 < 10) {
console.log("5 is less than 10");
} else {
console.log("5 is now bigger than 10")
}
Example 4: javascript for loop 5 times
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}
Example 5: javascript if
const number = (Math.random() - 2.5) * 5;
if (number < 0) {
console.log('Number is negative');
}
if (number = 0) {
console.log('Number is zero');
}
if (number > 0) {
console.log('Number is positive');
}