How does JavaScript’s prototypal inheritance differ from classical inheritance models?

  • JavaScript uses delegation-based inheritance, where objects inherit from other objects directly, not from classes.
  • JavaScript uses class-based inheritance like many other programming languages.
  • JavaScript's inheritance is more rigid and less flexible compared to classical models.
  • JavaScript's inheritance is limited to only built-in objects.
JavaScript's prototypal inheritance differs from classical inheritance models by using delegation-based inheritance. Instead of inheriting from classes, objects inherit directly from other objects, which is more flexible and dynamic.

In a NoSQL database like MongoDB, how are schemas defined and enforced?

  • Schemas are strictly enforced before data insertion
  • Schemas are defined using SQL
  • Schemas are flexible and can evolve with data
  • Schemas are predefined and cannot change
In NoSQL databases like MongoDB, schemas are flexible and can evolve with data. There's no strict enforcement of schemas before data insertion, allowing for schema-less data storage. This flexibility is one of the key features of NoSQL databases, making them suitable for handling unstructured or semi-structured data.

In Node.js, what is the purpose of the process.on('uncaughtException', handler) method?

  • To catch exceptions and continue program execution
  • To exit the Node.js process on any unhandled exception
  • To display uncaught exceptions in the console
  • To handle exceptions within a specific function
The process.on('uncaughtException', handler) method in Node.js is used to capture unhandled exceptions and prevent the Node.js process from crashing. It allows you to specify a custom handler function to handle these exceptions gracefully. The other options do not accurately describe the purpose of this method.

How can you create a deep copy of an object in JavaScript?

  • JSON.parse(JSON.stringify(object))
  • object.copy()
  • deepCopy(object)
  • Object.clone(object)
To create a deep copy of an object in JavaScript, you can use JSON.parse(JSON.stringify(object)). This method serializes the object to a JSON string and then parses it back into a new object, effectively creating a deep copy. The other options are not valid for deep copying objects.

In the context of closures, what is meant by the term 'lexical scoping' in JavaScript?

  • Lexical scoping, also known as static scoping, means that the scope of a variable is determined by its position within the source code, and it is fixed at the time of the variable's definition. In JavaScript, closures have lexical scoping, which means they capture variables from the outer function based on where they are defined in the code, not where they are executed.
  • Lexical scoping, also called static scoping, refers to the way variables are resolved in a program. In JavaScript closures, lexical scoping means that the scope of a variable is determined by its location in the source code, and it remains fixed once the function is defined.
  • Lexical scoping, often referred to as static scoping, is a feature of closures in JavaScript. It means that a closure captures variables from its surrounding context based on their lexical location, not their runtime values. This allows closures to access variables even after the outer function has completed execution.
  • In JavaScript closures, lexical scoping means that the scope of a variable is determined by its position in the code when the closure is defined, not when it is executed. This ensures that closures capture the correct variables from their enclosing scope.
Closures and Lexical Scoping

Which of the following is true about the prototype chain in JavaScript?

  • The prototype chain allows access to properties and methods of an object's prototype and its prototype's prototype, forming a chain.
  • The prototype chain only includes direct parent objects.
  • The prototype chain is static and cannot be modified dynamically.
  • The prototype chain is not used in JavaScript.
The prototype chain in JavaScript allows access to properties and methods of an object's prototype, its prototype's prototype, and so on, forming a chain. It is a fundamental concept in JavaScript's object-oriented programming.

To implement an authorization mechanism in Express.js effectively, developers often use ______ to manage user roles and permissions.

  • Passport.js
  • Express Passport
  • Sequelize
  • Mongoose
To implement an authorization mechanism in Express.js effectively, developers often use Passport.js. Passport.js is a popular authentication middleware for Node.js that supports various authentication strategies and can be used to manage user roles and permissions effectively. Sequelize and Mongoose are libraries for working with databases and are not directly related to authorization in Express.js.

Which method is used to attach a listener to an event in the Events module of Node.js?

  • addListener()
  • bindEvent()
  • attachEvent()
  • on()
To attach a listener to an event in the Events module of Node.js, you typically use the on() method. It's a common and standard way to register event handlers. Options A, B, and C are not commonly used for attaching listeners in Node.js.

In Node.js, the process.cwd() method returns the ________.

  • current working directory
  • home directory
  • root directory
  • parent directory
In Node.js, the process.cwd() method returns the current working directory of the Node.js process. This directory is the base directory from which the Node.js process was started.

What is the primary use of Streams in Node.js?

  • Managing database connections
  • Handling HTTP requests and responses
  • Storing configuration data
  • Sorting arrays
The primary use of Streams in Node.js is for handling data in a streaming fashion, especially for reading and writing data efficiently. They are commonly used for handling HTTP requests and responses, file I/O, and more, where data can be processed in smaller chunks without loading the entire dataset into memory.

What is the output of the following code snippet: console.log(1 == '1')?

  • TRUE
  • FALSE
  • undefined
The output of the code snippet is true. In JavaScript, the == operator performs type coercion, so it converts the string '1' to a number before comparing, and 1 is equal to 1.

In what scenarios would you implement custom middleware instead of using built-in middleware in Express.js?

  • Custom middleware should always be avoided, and built-in middleware should be used.
  • Custom middleware is necessary when working with database connections.
  • Custom middleware should be used when you need to perform application-specific logic that isn't covered by built-in middleware.
  • Custom middleware is used only for unit testing purposes.
Custom middleware is implemented in Express.js when you have specific application logic that cannot be handled by built-in middleware. Common scenarios include authentication, request logging, data validation, and handling application-specific errors. Built-in middleware covers common use cases, but custom middleware allows you to tailor the middleware pipeline to your application's unique needs.