General JS III
1.
How do you declare a constant variable with a numerical value in JavaScript?
var x = 42;
let x = 42;
const x = 42;
const x = '42';
2.
What does the `Array.indexOf()` method return if the specified element is not found in the array?
0
-1
null
undefined
3.
Which of the following statements correctly declares a function expression in JavaScript?
function myFunction(){};
var myFunction = function(){};
const myFunction = () => {};
let myFunction = function(){};
4.
What does the `Object.create()` method do in JavaScript?
Creates a shallow copy of an object
Modifies the existing object by adding new properties
Deletes all properties of an object
Creates a new object with the specified prototype object and properties
5.
How do you convert a string to a date object in JavaScript?
convertToDate(str);
Date.parse(str);
str.toDate();
new Date(str);
6.
What is the purpose of the `Array.every()` method in JavaScript?
Tests whether all elements in the array pass a provided function
Creates a new array with the results of calling a provided function on every element
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
7.
How would you check if a variable is an object in JavaScript?
if (x instanceof Object)
if (typeof x === 'object')
if (x.isObject())
if (x.type === 'object')
8.
What is the purpose of the `Array.pop()` method in JavaScript?
Adds one or more elements to the end of an array and returns the new length
Adds one or more elements to the beginning of an array and returns the new length
Removes the last element from an array and returns that element
Removes the first element from an array and returns that element
9.
How do you declare a global variable in JavaScript?
let myVar = 42;
global.myVar = 42;
var myVar = 42;
window.myVar = 42;
10.
What is the purpose of the `Array.reverse()` method in JavaScript?
Sorts the elements of an array in ascending order
Reverses the order of the elements in an array
Creates a new array with the results of calling a provided function on every element
Filters the elements of an array based on a given condition
11.
How do you remove the first element from an array in JavaScript?
arr.pop();
arr.shift();
arr.splice(0, 1);
arr.slice(1);
12.
What is the purpose of the `Array.some()` method in JavaScript?
Creates a new array with the results of calling a provided function on every element
Tests whether at least one element in the array passes a provided function
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
13.
How do you declare a multiline string in JavaScript?
var str = `This is a multiline string`;
var str = 'This is a \nmultiline string';
var str = '''This is a multiline string''';
var str = `This is a \ multiline string`;
14.
What does the `instanceof` operator do in JavaScript?
Checks if an object inherits from a specific prototype object
Checks if a variable is an instance of a specific type
Checks if an object is an instance of a specific class
Checks if a variable is defined
15.
How do you check if a function is defined in JavaScript?
if (myFunction.isDefined())
if (myFunction.exists())
if (typeof myFunction === 'defined')
if (typeof myFunction === 'function')
16.
What is the purpose of the `Array.join()` method in JavaScript?
Creates a new array with the results of calling a provided function on every element
Joins all elements of an array into a string
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
17.
How do you create a new line character in a string in JavaScript?
\r'
\n'
\t'
\n\r'
18.
What is the purpose of the `Array.splice()` method in JavaScript?
Removes the first element from an array and returns that element
Adds one or more elements to the end of an array and returns the new length
Removes the last element from an array and returns that element
Changes the contents of an array by removing or replacing existing elements
19.
How do you check if an object is empty in JavaScript?
if (Object.keys(myObj).length === 0)
if (myObj.length === 0)
if (Object.isEmpty(myObj))
if (myObj.isEmpty())
20.
What does the `String.trim()` method do in JavaScript?
Converts a string to uppercase
Adds whitespace to both ends of a string
Trims characters from the middle of a string
Removes whitespace from both ends of a string