What does the keyword "new" do in JavaScript?

  • Creates a class
  • Declares a variable
  • Instantiates an object
  • Defines a function
The keyword "new" in JavaScript is used to instantiate an object from a class constructor. When you use "new" followed by a class constructor, it creates a new instance of that class, allowing you to work with objects that have the properties and methods defined in the class. It doesn't create a class, declare a variable, or define a function.

An async function can contain an await expression that pauses the execution of the async function and waits for the passed _______ to resolve or reject.

  • callback
  • timeout
  • Promise
  • generator
An async function can contain an await expression that pauses the execution of the async function and waits for the passed Promise to resolve or reject. This allows for more readable and sequential asynchronous code, making it easier to work with asynchronous operations.

You are reviewing a junior developer's code and see the following line var x = 10;. You want to advise them to use a declaration that maintains block scope, which keyword should they use instead of var?

  • let
  • const
  • block
  • scope
Instead of var, they should use let to maintain block scope. var has function scope and can lead to unexpected behavior in certain situations, while let declares a variable with block scope, ensuring that it's limited to the block in which it's defined.

Which comparison operator performs type coercion if the operands are of different types?

  • == (Equality)
  • === (Strict Equality)
  • != (Inequality)
  • !== (Strict Inequality)
The comparison operator == (Equality) performs type coercion if the operands are of different types. This means JavaScript will attempt to convert the operands to the same type before making the comparison. In contrast, === (Strict Equality) checks both value and type without coercion.

Which of the following best describes a JavaScript callback function?

  • A function passed as an argument to another function and executed later
  • A function used to display pop-up messages
  • A function that runs immediately after it's defined
  • A function that loops through an array
A JavaScript callback function is a function that is passed as an argument to another function and is executed later, often after the completion of an asynchronous operation. It's a fundamental concept for handling asynchronous tasks and allows for flexible and event-driven programming.

Question 1: You are developing a web application and notice that when user-generated content is displayed on the page, it interprets HTML and JavaScript code. How can you prevent this behavior and enhance security?

  • Use the innerText property for rendering
  • Implement input validation and sanitization
  • Disable JavaScript in the browser
  • Use a stronger password policy
The most effective way to prevent user-generated content from executing JavaScript and potentially harmful code is to implement input validation and sanitization. By validating and sanitizing user inputs, you can strip or escape any potentially malicious code, making the content safe for display. Disabling JavaScript altogether may impact the functionality of your web application.

The pop() method removes the last element from an array and returns _______.

  • the popped element
  • the new array length
  • undefined
  • NaN
The pop() method in JavaScript removes the last element from an array and returns the removed element. If the array is empty, pop() returns undefined. It is commonly used to remove and retrieve the last element in a stack-like fashion from the end of an array.

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.