JavaScript Test 4

    Question 1String to Number Conversion

    What will be the result of "5" - 2 in JavaScript?

    Question 2Ternary Operator

    What is the result of let x = 10; let result = (x > 5) ? "Big" : "Small";?

    Question 3for...in Loop

    Which loop is used to iterate over object properties?

    Question 4Array Includes Check

    What will be the result of:

    let arr = [1, 2, 3]; console.log(arr.includes(2));

    Question 5Arrow Function this Behavior

    What is special about this in arrow functions?

    Question 6Object.freeze()

    What does Object.freeze(obj) do?

    Question 7this in setTimeout

    What does the following code output in a browser?

    setTimeout(function() { console.log(this); }, 1000);

    Question 8Removing Elements

    Which method removes a child node from the DOM?

    Question 9Spread Operator

    What does the following produce?

    let arr1 = [1, 2]; let arr2 = [...arr1, 3, 4];

    Question 10Handling Errors with Async/Await

    How do you properly catch errors in async/await?

    Question 11Implicit Conversion with + Operator

    What is the result of "5" + 2 in JavaScript?

    Question 12JS Modulus Operator

    What is the result of 17 % 5 in JavaScript?

    Question 13Break Statement

    What does the break statement do inside a loop?

    Question 14IndexOf Method

    What will be the result of:

    let arr = ["a", "b", "c"]; console.log(arr.indexOf("b"));

    Question 15IIFE (Immediately Invoked Function Expression)

    Which syntax correctly represents an IIFE?

    Question 16Object Destructuring

    What will this code output?

    let user = { name: "Alice", age: 22 }; let { name } = user; console.log(name);

    Question 17Execution Context

    How many phases does the JavaScript execution context have?

    Question 18Event Listener

    How do you add a click event listener to a button with ID btn?

    Question 19Object Property Shorthand

    What is the shorthand syntax for { name: name, age: age }?

    Question 20Promise.all()

    What does Promise.all([p1, p2, p3]) do?