| Output | Code |
|---|---|
|
JavaScript can change my content. |
|
|
//There are two ways to declare Array
let cities = new Array();
let cities = [];
cities =['Kolhapur', 'Pune', 'Mumbai']
//How to access array elements
console.log(cities[0])
console.log(cities[1])
//check log in browser for output
//There are two ways to declare Object
let car = new Object();
let car = {};
car = {
name: "A7",
brand: "Audi",
capacity: 5
};
//How to access properties of an Object
console.log(car['name'])
console.log(car['brand'])
//check log in browser for output
let age = 25;
if( age > 18)
{
console.log("My age is greater than 18");
}
else
{
console.log("My age is less than or 18");
}
//check log in browser for output
let age = 25;
if( age > 18)
{
console.log("My age is greater than 18");
}
else if(age >21)
{
console.log("My age is greater than 21");
}
else
{
console.log("My age is less than 18");
}
//check log in browser for output
for(var j=1; j<=7; j++)
{
console.log(j);
}
//check log in browser for output
var person = {name: "Shree", language: "JavaScript", age: 28};
for(var p in person)
{
console.log( p + " = " + person[p]);
}
//check log in browser for output
const evenno = [2,4,6,8,10];
evenno.forEach(showen);
function showen(item, index)
{
console.log(item);
}
//check log in browser for output
let x = 1, y = 6;
while (x <= y)
{
console.log(x);
x += 1;
}
//check log in browser for output
let a = 1;
let b =3;
do {
console.log(a);
a++;
} while(a <= b);
//check log in browser for output