How does the "this" keyword behave in arrow functions inside methods?

  • It refers to the instance of the class containing the method.
  • It refers to the global object (e.g., window in the browser).
  • It throws an error since arrow functions cannot be used inside methods.
  • It refers to the parent function's "this" value.
In arrow functions inside methods, the "this" keyword retains the value of the outer scope, typically the class instance. This behavior is different from regular functions, which have their own "this" binding. Understanding this behavior is crucial in object-oriented JavaScript programming.

The concept of closures and lexical scoping in JavaScript is based on the ________ principle.

  • Scope
  • Encapsulation
  • Abstraction
  • Inheritance
The concept of closures and lexical scoping in JavaScript is based on the "Scope" principle. In JavaScript, scope determines the accessibility of variables and functions in different parts of your code, and closures are a powerful feature that leverages lexical scope to maintain access to variables even after their containing functions have finished executing.

A _______ is a self-contained block of code that manipulates data, and can be thought of as an object in object-oriented programming.

  • Function
  • Module
  • Class
  • Closure
A Module is a self-contained block of code in JavaScript that manipulates data and can be thought of as an object in object-oriented programming. Modules help encapsulate functionality and data, providing a clean and organized code structure.

The _______ method returns the removed item when an element is removed from an array.

  • shift()
  • pop()
  • remove()
  • splice()
The pop() method in JavaScript removes the last element from an array and returns that removed element. It's useful when you need to remove and capture the last item in an array. For instance, let removed = myArray.pop() would remove the last element from myArray and store it in the removed variable.

In JavaScript, the _________ property is a reference to an object from which the current object inherits properties.

  • prototype
  • this
  • parent
  • child
In JavaScript, the prototype property is a reference to an object from which the current object inherits properties and methods. When you access a property or method on an object, JavaScript first looks for it on the object itself and then, if not found, on its prototype. Understanding prototypal inheritance is crucial in JavaScript.

How can you add a new property to a JavaScript object

  • a) By using the Object.assign() method.
  • b) By using the Object.addProperty() method.
  • c) By simply assigning a value to a new property name.
  • d) By using the addProperty() function.
You can add a new property to a JavaScript object by simply assigning a value to a new property name. For example, myObject.newProperty = 'some value';. While you can use methods like Object.assign() to copy properties from one object to another, it's not used for adding new properties. There's no Object.addProperty() or addProperty() method.

What does AJAX stand for in web development?

  • Asynchronous JavaScript and XML
  • Advanced JavaScript and XML
  • Asynchronous JavaScript and XHTML
  • Advanced JavaScript and HTML
AJAX stands for "Asynchronous JavaScript and XML." It is a set of web development techniques used to create asynchronous web applications. While XML was commonly used in the past, JSON is more prevalent today for data interchange in AJAX requests.

What is the purpose of the "else" statement in JavaScript?

  • To specify an alternate code block to execute when the condition is false
  • To terminate the program
  • To define a variable
  • To loop through an array
The "else" statement in JavaScript serves the purpose of specifying an alternate code block to execute when the condition specified in the "if" statement is false. It provides an alternative path for your code's execution.

What is the result of the expression NaN == NaN in JavaScript?

  • TRUE
  • FALSE
  • NaN
  • Throws an error
In JavaScript, NaN is not equal to itself. So, the expression NaN == NaN evaluates to false. This behavior is because NaN represents a value that is "Not-a-Number," and it's treated as unordered and not equal to any other value, including itself.

The main advantage of using arrow functions comes from the lack of a new _________ binding.

  • execution context
  • lexical scope
  • closure
  • variable
The main advantage of using arrow functions is that they do not create a new execution context or this binding. Instead, they capture the this value from their surrounding lexical scope. This behavior is known as "lexical scoping," and it provides a predictable way to maintain the value of this in various situations. Thus, the correct option is execution context.

You are asked to create an object that should be instantiated only once and reused in other instances. Which design pattern would you implement?

  • Singleton Pattern
  • Factory Pattern
  • Observer Pattern
  • Prototype Pattern
In this scenario, you would implement the Singleton Pattern. The Singleton Pattern ensures that a class has only one instance and provides a global point of access to that instance. It's useful when you need to maintain a single instance of an object that is shared across multiple parts of your application. This can help in scenarios such as creating a global configuration or managing a resource pool.

Which method is commonly used to send data as JSON using Fetch API?

  • fetch.post()
  • fetch.data()
  • fetch.sendJSON()
  • fetch()
The fetch() method is commonly used to send data as JSON using the Fetch API. To send JSON data, you can create a request object and use the JSON.stringify() method to convert your data into a JSON string before sending it.