General JS VIII
1.
How do you check if a variable is of type 'object' in JavaScript?
myVar instanceof Object
myVar.isObject()
myVar.type === 'object'
typeof myVar === 'object'
2.
What is the purpose of the `Math.pow()` function in JavaScript?
Rounds a number to the nearest integer
Returns the square root of a number
Returns the natural logarithm of a number
Returns the base to the exponent power
3.
How do you check if a string contains a specific substring in JavaScript?
str.contains('substring')
str.includes('substring')
str.indexOf('substring') !== -1
str.find('substring')
4.
What is the purpose of the `String.repeat()` method in JavaScript?
Converts a string to uppercase
Concatenates two strings
Replaces a specified substring with another substring
Returns a new string with a specified number of copies of the original string
5.
How do you declare a variable with a default value in JavaScript?
42;
var x = defaultValue
var x = 42
6.
What does the `String.slice()` method return if no arguments are provided?
`undefined`
The last character of the calling string
`null`
A shallow copy of the calling string
7.
How do you convert a number to a string in JavaScript?
num.toString()
String(num)
num.toStr()
String.valueOf(num)
8.
What is the purpose of the `encodeURIComponent()` function in JavaScript?
Decodes a URI component
Encodes a URI component
Encodes HTML entities
Decodes HTML entities
9.
How do you check if a number is positive or negative in JavaScript?
if (num < 0)
if (num.isPositive())
if (num >= 0)
if (num > 0)
10.
What is the purpose of the `String.trimEnd()` method in JavaScript?
Trims characters from the middle of a string
Adds whitespace to the end of a string
Removes whitespace from the end of a string
Converts a string to lowercase
11.
How do you declare a variable with a dynamic type in JavaScript?
const x = 42;
let x = 42;
var x = 42;
var x;
12.
What does the `String.concat()` method return if all arguments are empty strings?
An empty string
A new string with the same value as the calling string
`null`
`undefined`
13.
How do you convert a string to a boolean in JavaScript?
if (str === 'true')
str.toBoolean()
if (str) { /* code */ }
Boolean(str)
14.
What is the purpose of the `Object.create()` method in JavaScript?
Clones an existing object
Creates a new object with the specified prototype object and properties
Creates an array with the specified elements
Creates a new instance of a class
15.
How do you check if a variable is null in JavaScript?
if (myVar.isUndefined())
if (myVar.isNull())
if (myVar === undefined)
if (myVar === null)
16.
What does the `String.charCodeAt()` method return if the index is out of range?
`undefined`
`null`
`NaN`
An error is thrown
17.
How do you convert a string to a number with decimals in JavaScript?
str.toNumber()
Number.parseInt(str)
parseFloat(str)
parseInt(str)
18.
What is the purpose of the `Object.values()` method in JavaScript?
Returns an array of a given object's keys
Returns an array of a given object's own and inherited property values
Returns an array of a given object's own enumerable property values
Returns an array of a given object's keys and values
19.
How do you declare a constant variable with block scope in JavaScript?
let x = 42;
const x = 42;
var x = 42;
block const x = 42;
20.
What is the purpose of the `String.charAt()` method in JavaScript?
Replaces a specified character with another character
Returns the character at the specified index in a string
Returns the index of the first occurrence of a specified character in a string
Converts a string to lowercase