0% found this document useful (0 votes)
2K views3 pages

EXPERIMENT NO 5 WT

Uploaded by

shreyajadhav9700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views3 pages

EXPERIMENT NO 5 WT

Uploaded by

shreyajadhav9700
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO.

- 5
2203027
// 1. Data Types
let name = "shreya"; // String
let age = 20;// Number
let isStudent = true;// Boolean
let undefinedVar;// Undefined
let nullVar = null;// Null
let hobbies = ["playing", "listening music", "traveling"]; // Array (Object)
let person = { // Object
firstName: "shreya",
lastName: "jadhav",
age: 20,
isStudent: true
};
// Output some data types
console.log(`Name: ${name}`); // String interpolation
console.log(`Age: ${age}`);
console.log(`Is Student: ${isStudent}`);
console.log(`Hobbies: ${hobbies.join(", ")}`); // Array methods
console.log(`Person Info: ${person.firstName} ${person.lastName}, Age: $
{person.age}`);

// 2. Variables and Scope


var globalVar = "I'm accessible everywhere"; // Global scope
let blockScopedVar = "I'm accessible within block"; // Block scope
const constantVar = "I cannot be reassigned";
// Reassigning variables
blockScopedVar = "New value";
// Constant, can't be changed

// 3. Control Structures

// a) If-else statement
if (age >= 18) {
console.log("You are an adult.");
} else {
console.log("You are a minor.");
}

// b) Switch statement
let day = 2;
switch (day) {
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
case 3:
console.log("Wednesday");
break;
default:
console.log("Not a valid day");
}

// c) For Loop
for (let i = 0; i < hobbies.length; i++) {
console.log(`Hobby ${i + 1}: ${hobbies[i]}`);
}

// d) While Loop
let count = 1;
while (count <= 3) {
console.log(`Count: ${count}`);
count++;
}

Output :

You might also like