Which method should be used to handle exceptions in an async/await function?
- try...catch
- if...else
- switch...case
- throw...catch
To handle exceptions in an async/await function, you should use the 'try...catch' statement. This allows you to wrap the awaited code in a 'try' block and catch any exceptions that may occur within the 'catch' block. Using 'try...catch' ensures that your program can gracefully handle errors and prevent them from crashing your application.
Which of the following is NOT a type of polymorphism supported by JavaScript?
- Compile-time polymorphism
- Runtime polymorphism
- Ad-hoc polymorphism
- Parametric polymorphism
JavaScript supports runtime polymorphism and ad-hoc polymorphism (also known as function overloading), allowing different behavior for functions with the same name but different parameters. Parametric polymorphism is associated with generics and is not a form of polymorphism in JavaScript.
The _________ property of the XMLHttpRequest object holds the status of the XMLHttpRequest.
- statusText
- response
- status
- readyState
The status property of the XMLHttpRequest object holds the HTTP status code of the response received from the server. It indicates whether the request was successful or encountered an error. statusText contains the status message associated with the status code. response contains the response data.
How do you declare a two-dimensional array in JavaScript?
- let arr = [[]];
- let arr = [][[]];
- let arr = [[], []];
- let arr = [[],] [[]];
In JavaScript, a two-dimensional array is declared by creating an array where each element is another array. This creates a matrix-like structure. For example, let arr = [[], []]; declares a 2x2 two-dimensional array. The other options contain syntax errors or do not create a valid two-dimensional array.
In order to create a private variable in JavaScript, you might utilize a ________.
- Closure
- Prototype
- Constructor
- Module
In order to create a private variable in JavaScript, you might utilize a "Module." A module is a design pattern that allows you to encapsulate data and functions, providing a way to create private variables and methods. This helps in achieving data encapsulation and preventing unwanted external access.
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.