When a function is defined inside another function and has access to the outer function’s variables, the inner function is known as a _________.

  • Nested Function
  • Inner Function
  • Callback Function
  • Closure
A closure is a JavaScript feature where a function has access to variables from its containing (enclosing) function's scope even after the outer function has finished executing. It's a powerful concept for maintaining data privacy and creating functions that remember and can access their outer scope.

How does the "this" keyword behave in arrow functions compared to regular functions?

  • It refers to the global object.
  • It retains the value of "this" from its enclosing lexical context.
  • It becomes undefined.
  • It refers to the parent function's "this".
In arrow functions, the value of "this" is determined by its enclosing lexical context (the function that contains it). This behavior is different from regular functions, where "this" is dynamically scoped and can change based on how the function is called. This makes arrow functions particularly useful for maintaining the expected value of "this" in functions defined within methods or callbacks.

What is a key difference between arrow functions and regular functions in JavaScript?

  • Arrow functions have their own 'this' context
  • Regular functions are more concise
  • Arrow functions cannot have parameters
  • Regular functions do not allow for anonymous functions
One significant difference between arrow functions and regular functions is that arrow functions do not have their own 'this' context; instead, they inherit 'this' from the surrounding code. Regular functions, on the other hand, have their own 'this' context, which can vary depending on how the function is called.

During a code review, you spot the splice() method being used to remove an element from the end of an array. What alternative method might you suggest for removing elements from the end of an array that might be more performant and simpler?

  • pop()
  • shift()
  • slice()
  • push()
To remove an element from the end of an array, it's more efficient and simpler to use the pop() method. The pop() method removes the last element from the array and returns it, ensuring O(1) time complexity, whereas splice() is unnecessary for this task and can be less efficient.

How does JavaScript handle non-strict equality (==) comparisons in switch statements?

  • It uses strict equality (===) for comparisons.
  • It converts both the expression and case values to the same type before comparing.
  • It evaluates the expression and case values as-is without any type conversion.
  • It throws an error for non-strict equality comparisons.
JavaScript uses non-strict (loose) equality (==) comparisons in switch statements. It evaluates the expression and case values without any type conversion. This means that values with different types may be considered equal if their "abstract equality" holds true. For example, '1' == 1 is true.

What is the significant difference between Java and JavaScript?

  • Java is primarily a client-side language
  • JavaScript is a compiled language
  • Java is a strongly typed language
  • JavaScript is primarily used for web scripting
The significant difference between Java and JavaScript lies in their purpose and usage. Java is primarily a server-side language, whereas JavaScript is used for client-side web scripting. Additionally, Java is a statically typed language, while JavaScript is dynamically typed, which means variable types are determined at runtime. Understanding these differences is essential when choosing the right language for a particular task.

Which type of event listener will not get removed by the removeEventListener method?

  • Inline event listeners
  • Anonymous event listeners
  • Named function event listeners
  • Arrow function event listeners
Event listeners added using named functions can be removed with the removeEventListener method because they are given a reference to the function. In contrast, inline event listeners, anonymous functions, and arrow functions are not easily removed because they lack a reference. This makes them more challenging to manage and clean up in your code.

Which of the following methods mutates the original array?

  • map()
  • filter()
  • concat()
  • reduce()
The concat() method is used to concatenate two or more arrays and returns a new array. It does not mutate the original array. In contrast, methods like map(), filter(), and reduce() can modify the original array, so they should be used with caution.

The problem of multiple nested callbacks in JavaScript is commonly referred to as ________.

  • callback hell
  • nested loop
  • async overload
  • function maze
The problem of multiple nested callbacks in JavaScript is commonly referred to as "callback hell." It occurs when callback functions are heavily nested, making the code hard to read and maintain. This can lead to readability and maintenance issues.

Which array method removes the first element from an array and returns that removed element?

  • shift()
  • unshift()
  • pop()
  • push()
The array method that removes the first element from an array and returns that removed element is shift(). It shifts all other elements to a lower index, effectively removing the first element. The unshift() method adds elements to the beginning, pop() removes the last element, and push() adds elements to the end of the array.

What does the term "scope" refer to in JavaScript?

  • The physical size of a webpage
  • The lifetime of a variable
  • The visibility of a variable
  • The security of a webpage
In JavaScript, "scope" refers to the visibility or accessibility of a variable within a specific part of your code. It determines where in your code a particular variable can be used, which helps prevent naming conflicts and maintain code organization.

What is the primary role of the setTimeout function in asynchronous JavaScript?

  • Delaying code execution
  • Executing code repeatedly
  • Scheduling tasks
  • Controlling the event loop
The primary role of the setTimeout function is to delay the execution of a piece of code for a specified amount of time (in milliseconds). It allows you to schedule a function to run after a specified delay, making it useful for creating timeouts and delays in asynchronous code.