0% found this document useful (0 votes)
12 views2 pages

Unit3 JavaScript

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

Unit3 JavaScript

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

Web Technology – Practice Set

Unit 3: JavaScript

Q1. Describe JavaScript data types.


• Primitive: string, number, boolean, null, undefined, symbol, bigint
• Non-Primitive: object, array, function

Q2. Explain var, let and const with differences.


var let const

Scope Function Block Block

Re-declare Yes No No

Re-assign Yes Yes No

Hoisted Yes No No

Q3. What are JavaScript operators?


• Arithmetic: +, -, *, /, %
• Comparison: ==, ===, !=, >, <
• Logical: &&, ||, !
• Assignment: =, +=, -=
• Ternary: condition ? val1 : val2

Q4. Define JavaScript functions.


// Declaration
function greet(name) { return "Hello " + name; }

// Expression
const add = function(a, b) { return a + b; };

// Arrow function
const multiply = (a, b) => a * b;

Q5. What are control statements in JavaScript?


• Decision: if/else, else if, switch
• Loops: for, while, do-while
• Loop control: break, continue

Q6. Write a JavaScript program to check even and odd.


let num = 7;
if (num % 2 === 0) {
[Link](num + " is Even");
} else {
[Link](num + " is Odd");
}

Q7. Write a JavaScript program using loops.


// for loop
for (let i = 1; i <= 5; i++) [Link](i);

// while loop
let i = 1;
while (i <= 5) { [Link](i); i++; }

// do-while loop
let j = 1;
do { [Link](j); j++; } while (j <= 5);

Q8. Write a JavaScript program using functions.


function factorial(n) {
if (n === 0) return 1;
return n * factorial(n - 1); // Recursion
}
[Link](factorial(5)); // Output: 120

Q9. Write a JavaScript program using arrays.


let fruits = ["Apple", "Banana", "Mango"];
[Link]("Orange"); // Add element
[Link](); // Remove last
[Link]([Link]); // 3
[Link](f => [Link](f));

// Array methods
let nums = [3, 1, 4, 1, 5];
[Link]((a,b) => a - b); // Sort ascending
let doubled = [Link](n => n * 2);

Q10. Write a JavaScript program using objects.


let student = {
name: "Alice",
age: 20,
greet: function() {
return "Hi, I am " + [Link];
}
};
[Link]([Link]); // Alice
[Link]([Link]); // 20
[Link]([Link]()); // Hi, I am Alice

// Add new property


[Link] = "A";
[Link]([Link]); // A

You might also like