What does the async keyword do in front of a function in JavaScript?

  • Marks the function as asynchronous
  • Declares a synchronous function
  • Makes the function execute faster
  • Signals the end of a function call
Adding the async keyword before a function declaration in JavaScript signifies that the function is asynchronous. This means it can use the await keyword inside to pause execution until asynchronous operations within the function are complete, improving code readability and maintainability.

The ________ initiative aimed to standardize the core features of JavaScript.

  • ECMAScript
  • JavaScriptCore
  • JSStandard
  • WebScript
The ECMAScript initiative aimed to standardize the core features of JavaScript. ECMAScript defines the language specification that JavaScript implementations, such as those in web browsers, must adhere to. It ensures consistency and compatibility across different environments.

Which technology was NOT directly influenced by JavaScript's development?

  • JSON (JavaScript Object Notation)
  • Java
  • Node.js
  • jQuery
While JavaScript and JSON share a similar name, JSON (JavaScript Object Notation) is a data interchange format and not a technology directly influenced by JavaScript's development. Java, Node.js, and jQuery, on the other hand, are technologies that were influenced or built upon JavaScript.

How to declare a block-scoped variable in JavaScript?

  • var keyword
  • const keyword
  • let keyword
  • block keyword
In JavaScript, you can declare a block-scoped variable using the let keyword. Variables declared with let are limited in scope to the block, statement, or expression in which they are defined. This helps prevent unintended variable hoisting and allows you to create variables with localized scope within functions or blocks. var is function-scoped, and const is used to declare constants. block is not a valid keyword for variable declaration.

You are building a single-page application, and you want to make an API call. You realize that you want to abort the fetch request if the user navigates away from the current page to avoid unnecessary data transfer. How can you achieve this?

  • Use the fetch.abort() method to cancel the request when the user navigates away.
  • Implement an if statement to check the navigation state and cancel the request accordingly.
  • Set a timeout for the fetch request and cancel it if the user navigates away within the timeout period.
  • There's no way to cancel a fetch request when the user navigates away.
To abort a fetch request when the user navigates away from the current page, you should implement an if statement that checks the navigation state and cancels the request accordingly. The other options are not suitable for this specific task, and there's no built-in fetch.abort() method in JavaScript.

You're reviewing a pull request, and you see that a developer used var to declare a variable inside a for loop. You notice that the variable is being accessed outside the loop without any issues. Why is this possible?

  • Variable Hoisting
  • Block Scoping (let/const)
  • Function Scoping
  • Global Scope
This is possible due to "Variable Hoisting" in JavaScript. Variables declared with var are hoisted to the top of their containing function or global scope. This means that the variable is accessible anywhere within that scope, even before its actual declaration in the code.

The break statement exits a while loop and continues executing the code that follows the loop at line number ________.

  • immediately
  • next
  • specified
  • labeled
The 'break' statement exits a while loop immediately and continues executing the code that follows the loop at the next line. It allows you to prematurely terminate a loop based on a certain condition, without completing the remaining iterations.

In which scenario is a function expression preferred over a function declaration?

  • When you need the function to be hoisted and accessible before its declaration in the code.
  • When you want to declare a function as a named function to improve code readability and debugging.
  • When you need to define a function inside an object or as a callback function in another function.
  • When you want to declare a function as a global function for reuse across multiple scripts.
A function expression is preferred over a function declaration when you need to define a function inside an object, pass it as a callback function, or use it in a specific local scope. Function expressions are often used in scenarios where you want to create functions on the fly and keep them within a limited scope.

The data type of NaN in JavaScript is _________.

  • Not a Number (NaN)
  • Number
  • Undefined
  • String
The data type of NaN in JavaScript is "Not a Number" (NaN). NaN is a special value representing an unrepresentable or undefined value in the context of numbers. It is not a regular number, undefined, or a string. Understanding the data type of NaN is important for handling unexpected mathematical operations in JavaScript.

To select elements with a specific class name, you should use the __________ method.

  • getElementById()
  • getElementByClass()
  • querySelectorAll()
  • querySelector()
To select elements with a specific class name, you should use the querySelector() method. This method allows you to select elements using CSS-like selectors, including class names. For example, document.querySelector('.classname') selects all elements with the specified class name.