In JavaScript, you can add a new property to an object by simply assigning a value to it with the _________ operator.
- add
- extend
- assign
- new
In JavaScript, you can add a new property to an object by simply assigning a value to it with the assign operator. The assign operator is used to add or update properties on an object. It's a common operation for dynamically working with objects and their properties in JavaScript.
The _______ method is used to handle errors in Promises.
- .then()
- .catch()
- .resolve()
- .reject()
The correct method to handle errors in Promises is the .catch() method. When a Promise is rejected, the .catch() method is called with the reason for the rejection, allowing you to handle and manage errors in your asynchronous code effectively.
How do you denote a block of code to be executed if a condition is true?
- By enclosing it in curly braces {}
- By using square brackets []
- By using parentheses ()
- By using angle brackets <>
In JavaScript, you denote a block of code to be executed if a condition is true by enclosing it in curly braces {}. These braces create a code block that allows you to execute multiple statements when the condition is met.
What is a potential downside of using async/await syntax?
- It makes code harder to read and understand.
- It can't be used with Promises.
- It always leads to callback hell.
- It reduces code efficiency.
One potential downside of using async/await is that it can make code harder to read and understand, especially for developers who are not familiar with asynchronous programming. It may lead to nested code blocks, which can be challenging to follow. However, when used correctly, async/await can make asynchronous code more readable.
JavaScript was introduced to the world in the year _________.
- 1995
- 2000
- 1998
- 1993
JavaScript was introduced to the world in the year 1995. It was first released by Netscape as part of their Navigator 2.0 web browser. JavaScript quickly gained popularity as a client-side scripting language for web development.
Which organization developed JavaScript?
- Microsoft
- Mozilla
- Netscape
- Oracle
JavaScript was developed by Netscape. Brendan Eich created it in 10 days in September 1995. While Netscape is best known for its role in the development of JavaScript, it didn't create other popular languages like Java.
What is the output of the arithmetic expression 7 / 0 in JavaScript?
- 0
- Infinity
- NaN (Not-a-Number)
- Error
The output of the arithmetic expression 7 / 0 in JavaScript is Infinity. In JavaScript, dividing a number by 0 results in positive or negative infinity depending on the sign of the numerator. Attempting to divide by 0 does not throw an error, but it produces infinity.
The _______ pattern is used to create an instance of an object with some default values.
- Factory
- Prototype
- Singleton
- Observer
The Factory pattern is used to create an instance of an object with some default values. It provides an interface for creating objects in a super factory or a factory method. This pattern is commonly used in JavaScript to create objects.
When a function expression is made async, it returns a ______.
- Promise
- Callback
- Generator
- Class
When a function expression is marked as "async," it returns a Promise. An async function can pause its execution and wait for the Promise to resolve or reject, which is helpful for handling asynchronous operations elegantly.
A do-while loop is particularly useful when you want to ensure the loop body executes at least ________ before checking the condition.
- Once
- Twice
- Never
- Once or more
A do-while loop is useful when you want to guarantee that the loop body executes at least "once" before checking the condition. This is because in a do-while loop, the condition is evaluated after the loop body, ensuring that the code inside the loop executes at least once, even if the condition is initially false.