General JS VII
1.
How do you check if a variable is of type 'undefined' in JavaScript?
myVar.type === 'undefined'
myVar.isUndefined()
typeof myVar === 'undefined'
myVar === undefined
2.
What is the purpose of the `String.concat()` method in JavaScript?
Splits a string into an array of substrings
Concatenates two or more strings
Converts a string to uppercase
Removes whitespace from both ends of a string
3.
How do you declare a variable with a global scope in JavaScript?
global.myVar = 42;
var myVar = 42;
let myVar = 42;
window.myVar = 42;
4.
What is the purpose of the `String.search()` method in JavaScript?
Returns the index within the calling string of the first occurrence of the specified value
Replaces a specified substring with another substring
Searches a string for a specified value and returns the position of the match
Returns a boolean indicating whether the calling string contains the specified value
5.
How do you declare a variable with a constant value in JavaScript?
var x = 42;
let x = 42;
const x = 42;
x.const(42);
6.
What is the purpose of the `String.toUpperCase()` method in JavaScript?
Returns the last character of a string
Converts a string to lowercase
Returns the length of the calling string
Converts a string to uppercase
7.
How do you declare a function with parameters in JavaScript?
let myFunction = (param1, param2) => {}
const myFunction = function(param1, param2)
function myFunction(param1, param2)
myFunction = function(param1, param2)
8.
What does the `Object.getOwnPropertyDescriptor()` method return in JavaScript?
The value of a specified property
An object describing the configuration of a specific property
An array of a given object's own enumerable property key-value pairs
The prototype object of a specified property
9.
How do you convert a string to lowercase in JavaScript?
str.lowercase()
str.toLower()
str.caseLower()
str.toLowerCase()
10.
What is the purpose of the `Number.isNaN()` method in JavaScript?
Returns a boolean indicating whether a value is NaN
Determines whether a value is NaN and its type is Number
Converts a value to NaN
Checks if a variable is of type NaN
11.
How do you declare a variable with block scope that cannot be reassigned in JavaScript?
const x = 42;
let x = 42;
var x = 42;
block x = 42;
12.
What does the `Object.getPrototypeOf()` method return in JavaScript?
The configuration of a specified property
The value of the specified property
An array of a given object's own enumerable property key-value pairs
The prototype of the specified object
13.
How do you remove all whitespace from a string in JavaScript?
str.strip()
str.removeAllWhitespace()
str.trim()
str.replace(/\s/g, '')
14.
What is the purpose of the `String.charCodeAt()` method in JavaScript?
Converts a string to lowercase
Returns the Unicode value of the character at the specified index in a string
Returns the index of the first occurrence of a specified character in a string
Returns the last character of a string
15.
How do you check if a number is an integer in JavaScript?
x.isInteger()
Number.isInteger(x)
typeof x === 'integer'
x % 1 === 0
16.
What is the purpose of the `String.trimStart()` method in JavaScript?
Trims characters from the middle of a string
Adds whitespace to the beginning of a string
Removes whitespace from the beginning of a string
Converts a string to uppercase
17.
How do you declare a variable with a default value if it is undefined, null, or an empty string?
defaultValue;
var x = myVar
var x = defaultValue
18.
What does the `String.concat()` method return if no arguments are provided?
An empty string
A new string with the same value as the calling string
`null`
`undefined`
19.
How do you convert a boolean to a number in JavaScript?
Number(myBool)
myBool.toNumber()
parseInt(myBool)
myBool.convertToNumber()
20.
What does the `String.charAt()` method return if the index is out of range?
`undefined`
`null`
An empty string
An error is thrown