For Loops in JavaScript

 for (let i = 0; i < 10; i++) {

    console.log(i);
}

//Program to add first n natural numbers
let sum = 0
let n = prompt("Enter the value of n");
n = Number.parseInt(n);
for (let i = 0; i <= n; i++) {
    sum = sum + i;
}
console.log("Sum of first " + n + " natual numbers is " + sum);

let obj = {
    harry: 90,
    shubh: 45,
    shivika: 56,
    ritika: 57,
    shiv: 23
}
//For in loop
for (let a in obj) {
    console.log("Marks of " + a + " are " + obj[a]);
}

//For of loop
for (let b of "Harry") {
    console.log(b);
}

Comments

Popular posts from this blog

Symbols tutorial in Advance JavaScript

Async and Await Method tutorial in Advance JavaScript

String Methods in JavaScript