JavaScript Test 5

    Question 1Undefined Value Type

    What is the type of undefined in JavaScript?

    Question 2Unary Increment

    What is the result of:

    let a = 5; let b = ++a;

    Question 3JS Continue Statement

    What is the output?

    for (let i = 0; i < 5; i++) { if (i === 2) continue; console.log(i); }

    Question 4Array isArray Method

    What is the result of:

    console.log(Array.isArray([1, 2, 3]));

    Question 5JS Default Parameters

    What will greet("Alice") print if the function is defined as:

    function greet(name = "Guest") { console.log(name); }

    Question 6JS For...in Loop

    What is the output?

    let obj = {a:1, b:2}; for (let key in obj) { console.log(key); }

    Question 7Types of Execution Context

    Which of the following are types of execution context in JavaScript?

    Question 8Query Selector

    Which method selects the first element that matches a CSS selector?

    Question 9Rest Parameters

    Which function correctly uses rest parameters to accept multiple arguments?

    Question 10Multiple await Statements

    How does execution behave with multiple await statements?

    Question 11Equality with Type Conversion

    What is the result of 0 == "0" in JavaScript?

    Question 12Exponentiation Operator

    What is the result of 2 ** 3 in JavaScript?

    Question 13Nested Loop Execution

    How many times will "Hello" be printed?

    for (let i = 0; i < 2; i++) { for (let j = 0; j < 3; j++) { console.log("Hello"); } }

    Question 14Array Concatenation

    What will be the result of:

    let a = [1, 2]; let b = [3, 4]; console.log(a.concat(b));

    Question 15Hoisting with Function Expressions

    What happens if you call a function expression before it is defined?

    greet(); var greet = function() { console.log("Hello"); };

    Question 16Object.assign()

    What does Object.assign(target, source) do?

    Question 17this Inside a Class

    What does the following code output?

    class Car { constructor(name) { this.name = name; } showName() { console.log(this.name); } } let c = new Car("Tesla"); c.showName();

    Question 18querySelectorAll vs getElementsByClassName

    What is the difference between querySelectorAll and getElementsByClassName?

    Question 19Modules Export/Import

    How do you export a function in ES6 module?

    Question 20Converting Promise to Async/Await

    Which of the following is equivalent to:

    fetchData().then(data => console.log(data)).catch(err => console.log(err));