0% found this document useful (0 votes)
9 views

JS Test

s2

Uploaded by

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

JS Test

s2

Uploaded by

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

1) What will be the output when example() is called?

function example() {
console.log(a);
var a = 10;
console.log(a);
}
example();

2) What will be the output of printNumbers()? Explain why.

let x = 5;
function foo() {
x = 10;
}
foo();
console.log(x);

3) What will be the output of printNumbers()? Explain why

a) function printNumbers() {
for (var i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, 100);
}
}
printNumbers();

b) function printNumbers() {
for (let i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, 100);
}
}
printNumbers();

4) What will be the output.

const obj = { name: 'Alice', age: 30 };

let name, age;


for (const key in obj) {
if (key === 'name') {
name = obj[key];
} else if (key === 'age') {
age = obj[key];
}
}

console.log('Name:', name);
console.log('Age:', age);

5) What will be the output when outer() is called?


function outer() {
let a = 1;
function inner() {
let b = 2;
console.log(a + b);
}
inner();
}
outer();

6) What will be the output of the above code Explain?

function greeting(name = 'Anonymous') {


return `Hello, ${name}!`;
}
console.log(greeting());

7) What are the different data types present in javascript?

8) Difference between “ == “ and “ === “ operators.

9) Difference between var and let keyword in javascript.

10) What is an Immediately Invoked Function in JavaScript?

11) What are callbacks?

12) What is DOM?

13) What are arrow functions?

14) What is the rest parameter and spread operator?

15) What is the use of promises in javascript explain with an example?

16) let people = [


{
name: "John",
age: 30,
occupation: "Engineer"
},
{
name: "Alice",
age: 25,
occupation: "Teacher"
},
{
name: "Bob",
age: 35,
occupation: "Doctor"
},
{
name: "Eve",
age: 28,
occupation: "Artist"
}
];

a1) How can I access the name and age of the second person in the array?
a2) What is the occupation of the last person in the array?
a3) Show me how to access and print all the names of the people in the array

b1) How can I change John's age to 32?


b2) Update Eve's occupation to "Graphic Designer".
b3) Add a new person with name "Michael", age 40, and occupation "Lawyer" to the
array.

c1) How can I filter out people who are younger than 30?
c2) Show me all the people who have "Engineer" as their occupation.
c3) How do I get an array of people's names who are older than 30?

You might also like