Which of the following array methods does NOT modify the original array?

  • splice()
  • slice()
  • map()
  • filter()
The slice() method does NOT modify the original array. Instead, it returns a new array containing a shallow copy of elements from the original array. You can specify a range of indices to slice from the original array. This is useful when you want to extract a portion of the array without altering the original data. The other methods, splice(), map(), and filter(), can modify the original array.

Which keyword is used to declare a variable in JavaScript?

  • var
  • variable
  • declare
  • v
In JavaScript, you declare a variable using the var keyword. For example, var myVariable; declares a variable named myVariable. Other keywords like let and const are also used for variable declarations in modern JavaScript.

The callback function in asynchronous JavaScript is invoked

  • Event Loop
  • Callback
  • JavaScript Engine
  • Event Handler
The callback function in asynchronous JavaScript is invoked by the Event Loop when the asynchronous operation is complete. The Event Loop is a crucial component of JavaScript's runtime that ensures asynchronous tasks are executed in the correct order.

The replaceChild method requires _________ arguments.

  • 3
  • 2
  • 1
  • 4
The replaceChild method in JavaScript DOM manipulation requires two arguments: the new node to be inserted and the node to be replaced. This method is commonly used to swap one DOM element with another.

Using _______ in front of a Promise-based function call makes JavaScript wait until that Promise settles and returns its result.

  • Wait
  • Hold
  • Async
  • Await
The keyword await is used in front of a Promise-based function call to make JavaScript wait for that promise to resolve or reject before proceeding with the code execution. It allows for writing asynchronous code in a more synchronous-like manner.

In a scenario where you have to create a function that acts differently based on the type of input (string, number, or boolean), how might you implement this using a switch statement?

  • Use separate case statements for each data type, and within each case, handle the specific behavior for that data type.
  • Convert the input to a string, and then use a single case statement for "string", "number", and "boolean" as switch cases.
  • Create individual functions for each data type and call the appropriate function based on the input type.
  • Use an if-else ladder instead of a switch statement to handle different data types.
When implementing a function that acts differently based on input types using a switch statement, it's best practice to use separate case statements for each data type. This ensures clarity and maintainability of your code, as each case can handle the specific behavior for that data type. Using a single case statement with type conversion is less readable and may lead to unexpected behavior. Individual functions for each type would increase code complexity unnecessarily, and using an if-else ladder is less efficient and less idiomatic in JavaScript.

How do you access the first element of an array named myArray?

  • myArray[0]
  • myArray.firstElement()
  • myArray.first()
  • myArray.getElement(1)
You can access the first element of an array named myArray by using the square bracket notation with an index of 0, like myArray[0]. This is because JavaScript arrays are zero-indexed, so the first element is at index 0. The other options are not valid ways to access the first element of an array.

What will happen if the condition in the "for" loop is always true?

  • The loop will run indefinitely
  • The loop will not run
  • The loop will run only once
  • The loop will skip iterations
If the condition in a "for" loop is always true, the loop will run indefinitely, resulting in an infinite loop. This can cause the program to become unresponsive or crash, so it's crucial to ensure that the loop condition eventually becomes false to exit the loop.

Which of the following is a method to create an object in JavaScript?

  • Object.create()
  • new Object()
  • createObject()
  • initializeObject()
In JavaScript, you can create an object using the Object.create() method. This method allows you to specify the prototype object from which the new object should inherit properties and methods. The new Object() syntax is less commonly used for object creation.

When would you want to use Object.create(null) instead of {} to create a new object?

  • When you need an object with no prototype chain to avoid inheriting properties or methods unintentionally.
  • When you want an object that can't be modified or extended further.
  • When you need an object with a predefined set of properties and methods for a specific use case.
  • When you want to create an empty object with the default prototype chain.
Object.create(null) is used when you need an object with no prototype chain (a "null prototype"), which means it won't inherit any properties or methods from Object.prototype. This can be useful for creating objects where you want complete control over the properties and avoid unintentional inheritance.

To declare a string variable named text with the value 'Hello World' in JavaScript, you would write _________.

  • var text = "Hello World";
  • var text := "Hello World";
  • string text = "Hello World";
  • text = "Hello World";
To declare a string variable in JavaScript, you use the var keyword followed by the variable name (text) and assign the value (Hello World) using the equal sign (=). The correct syntax is var text = "Hello World";. Variables are case-sensitive in JavaScript, so make sure the variable name matches the case.

The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to _______ it to a single value.

  • multiply
  • concatenate
  • reduce
  • filter
The reduce() method in JavaScript is used to apply a function to an accumulator and each element of the array (from left to right) to reduce it to a single value. It's often used for tasks like summing up values or aggregating data. The correct option is reduce.