General JS V
1.
What is the purpose of the `Object.assign()` method in JavaScript?
Returns an array of a given object's own enumerable property key-value pairs
Combines two or more arrays
Copies the values of all enumerable properties from one or more source objects to a target object
Creates a new object with the specified prototype object and properties
2.
How do you check if a variable is a boolean in JavaScript?
if (myVar.type === 'boolean')
if (typeof myVar === 'boolean')
if (myVar.isBool())
if (myVar === true || myVar === false)
3.
What is the purpose of the `JSON.stringify()` method in JavaScript?
Converts a JSON string to a JavaScript object
Converts a JavaScript object to a JSON string
Parses a string and returns an integer
Encodes a JavaScript object into JSON format
4.
How do you declare a variable with block scope in JavaScript?
var x = 10;
let x = 10;
const x = 10;
block x = 10;
5.
What is the purpose of the `String.replace()` method in JavaScript?
Concatenates two strings
Replaces a specified substring with another substring
Returns the characters in a string between two specified indices
Converts a string to uppercase
6.
How do you create a date object representing the current date and time in JavaScript?
Date.create()
new Date.now()
Date.current()
new Date()
7.
What is the purpose of the `Math.random()` function in JavaScript?
Returns the square root of a number
Returns a random integer between two specified values
Returns a random floating-point number between 0 (inclusive) and 1 (exclusive)
Rounds a number to the nearest integer
8.
How do you convert a string to an array of characters in JavaScript?
str.toArray()
str.split('')
Array.from(str)
str.toCharArray()
9.
What is the purpose of the `String.indexOf()` method in JavaScript?
Returns a boolean indicating whether the calling string contains the specified value
Replaces a specified substring with another substring
Returns the index within the calling string of the first occurrence of the specified value
Returns the length of the calling string
10.
How do you convert a string to a number in JavaScript?
str.toNumber()
Number(str)
parseInt(str)
str.convertToNumber()
11.
What is the purpose of the `typeof` operator in JavaScript?
Checks if a variable is defined
Returns a string indicating the type of the unevaluated operand
Returns the data type of a variable
Converts a variable to a specific type
12.
How do you declare a function using the arrow function syntax in JavaScript?
const myFunction = () => {}
var myFunction = function(){};
function myFunction(){}
let myFunction = function(){};
13.
What is the purpose of the `setTimeout` function in JavaScript?
Clears the timer set by `setInterval`
Sets a timer for a specific time
Repeats a function at regular intervals
Delays the execution of a function for a specified amount of time
14.
How do you check if an object is an instance of a specific class in JavaScript?
if (myObj.isInstanceof(MyClass))
if (myObj.type === 'MyClass')
if (myObj instanceof MyClass)
if (myObj.instanceOf(MyClass))
15.
What is the purpose of the `String.charAt()` method in JavaScript?
Returns the index of the first occurrence of a specified character in a string
Replaces a specified character with another character
Returns the character at the specified index in a string
Converts a string to lowercase
16.
How do you concatenate two strings in JavaScript?
str1.combine(str2)
str1.concat(str2)
str1 + str2
str1.join(str2)
17.
What is the purpose of the `String.length` property in JavaScript?
Returns the last character of a string
Returns the first character of a string
Returns the number of characters in a string
Returns the index of the last occurrence of a specified character in a string
18.
How do you convert a number to a string with a specified number of decimal places in JavaScript?
num.toFixed(2)
num.toString(2)
num.toPrecision(2)
String.format(num, 2)
19.
How do you declare a variable with a default value if it is undefined or null?
var x = myVar ?? defaultValue;
var x = defaultValue || myVar;
var x = defaultValue ?? myVar;
var x = myVar || defaultValue;
20.
How do you check if a string ends with a specific substring in JavaScript?
str.beginsWith('substring')
str.endsWithSubstring('substring')
str.lastIndexOf('substring') === str.length - 1
str.endsWith('substring')