General JS IV
1.
What does the `Object.keys()` method return if the object is empty?
An object with a property named 'keys'
`null`
`undefined`
An empty array
2.
How can you check if a variable is a function in JavaScript?
if (myFunc.type === 'function')
if (myFunc.isFunction())
if (myFunc instanceof Function)
if (typeof myFunc === 'function')
3.
What is the purpose of the `Array.includes()` method in JavaScript?
Removes the first occurrence of a specific element from an array
Adds an element to the end of an array
Determines whether an array includes a certain element
Concatenates two arrays
4.
How do you convert a string to a floating-point number in JavaScript?
str.toFloat()
parseFloat(str)
Number.parseFloat(str)
parseFloatNumber(str)
5.
What is the purpose of the `Object.values()` method in JavaScript?
Returns an array of a given object's keys and values
Returns an array of a given object's own enumerable property values
Returns an array of a given object's own and inherited property values
Returns an array of a given object's keys
6.
How do you check if a variable is undefined or null in JavaScript?
if (myVar.isNullOrUndefined())
myVar === null)
if (myVar === undefined
7.
What is the purpose of the `Array.shift()` method in JavaScript?
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
Adds one or more elements to the beginning of an array and returns the new length
Removes the first element from an array and returns that element
8.
How do you declare a variable that cannot be reassigned in JavaScript?
let x = 42;
const x = 42;
var x = 42;
immutable x = 42;
9.
What is the purpose of the `encodeURIComponent()` function in JavaScript?
Decodes a JSON object
Decodes a URI component
Encodes a JSON object
Encodes a URI component
10.
How do you check if a property exists in an object in JavaScript?
if (myObj.hasOwnProperty('property'))
if (myObj.propertyExists())
if ('property' in myObj)
if (myObj.property !== undefined)
11.
What is the purpose of the `Object.entries()` method in JavaScript?
Returns an array of a given object's keys
Returns an array of a given object's own and inherited property key-value pairs
Returns an array of a given object's own enumerable property key-value pairs
Returns an array of a given object's values
12.
How do you declare a variable with a default value in JavaScript?
defaultValue;
var x = x
var x = defaultValue
13.
What is the purpose of the `Array.concat()` method in JavaScript?
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
Combines two or more arrays
Removes the first element from an array and returns that element
14.
How do you convert a number to a fixed number of decimal places in JavaScript?
Math.round(num, 2)
num.toPrecision(2)
num.round(2)
num.toFixed(2)
15.
What does the `Object.freeze()` method not prevent in JavaScript?
Modifying existing properties of the object
Adding new properties to the object
Deleting existing properties of the object
Preventing the object from being modified
16.
How do you convert a string to an uppercase in JavaScript?
str.toUpper()
str.toUpperCase()
str.caseUpper()
str.uppercase()
17.
What is the purpose of the `Array.fill()` method in JavaScript?
Reduces the array to a single value by applying a 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
Fills all elements of an array with a static value
18.
How do you create a copy of an object in JavaScript?
var copy = original.spread();
var copy = original.copy();
var copy = original.clone();
var copy = Object.assign({}, original);
19.
What is the purpose of the `String.substring()` method in JavaScript?
Trims whitespace from both ends of a string
Converts a string to lowercase
Converts a string to uppercase
Extracts characters between two specified indices
20.
What is the purpose of the `try...catch` statement in JavaScript?
Defines a block of code to be executed after the `catch` block
Defines a block of code to be executed regardless of whether an error occurs
Defines a block of code to be executed before the `try` block
Defines a block of code to be executed if an error occurs