General JS IX
1.
How do you check if a variable is a function in JavaScript?
myVar instanceof Function
myVar.isFunction()
myVar.type === 'function'
typeof myVar === 'function'
2.
What is the purpose of the `Array.splice()` method in JavaScript?
Concatenates two arrays
Changes the contents of an array by removing or replacing existing elements and/or adding new elements
Sorts the elements of an array
Returns a new array with the results of calling a function on every element
3.
How do you declare a variable with a global scope in JavaScript?
let myVar = 42;
var myVar = 42;
window.myVar = 42;
global.myVar = 42;
4.
What is the purpose of the `String.link()` method in JavaScript?
Encodes a URI component
Creates an HTML anchor element with the specified URL
Converts a string to lowercase
Trims whitespace from both ends of a string
5.
How do you check if an object is frozen in JavaScript?
myObj.isSealed()
myObj.frozen()
myObj.freezeStatus()
Object.isFrozen(myObj)
6.
What is the purpose of the `Number.toExponential()` method in JavaScript?
Returns the exponent of a number
Returns a string representing a number in exponential notation
Rounds a number to the nearest integer
Converts a number to a string
7.
How do you remove the last element from an array in JavaScript?
arr.removeLast()
arr.slice(-1)
arr.pop()
arr.splice(-1)
8.
What is the purpose of the `Date.toISOString()` method in JavaScript?
Returns the current date and time in the local time zone
Returns a string representing a date and time in UTC format
Returns the number of milliseconds since January 1, 1970, 00:00:00 UTC
Converts a date to a string in the specified format
9.
How do you declare a variable with block scope in JavaScript?
block x = 10;
var x = 10;
const x = 10;
let x = 10;
10.
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
11.
How do you declare a variable with a constant value in JavaScript?
let x = 42;
const x = 42;
var x = 42;
x.const(42);
12.
What is the purpose of the `String.anchor()` method in JavaScript?
Trims whitespace from both ends of a string
Adds an anchor element to the end of a string
Creates an HTML anchor element with the specified name
Converts a string to lowercase
13.
How do you declare a function with parameters in JavaScript?
const myFunction = function(param1, param2)
function myFunction(param1, param2)
let myFunction = (param1, param2) => {}
myFunction = function(param1, param2)
14.
What is the purpose of the `Object.defineProperty()` method in JavaScript?
Removes a property from an object
Returns an array of a given object's own enumerable property key-value pairs
Adds or modifies a property of the object with a specified descriptor
Seals an object, preventing new properties from being added and existing properties from being deleted
15.
How do you convert a string to uppercase in JavaScript?
str.toUpper()
str.toUpperCase()
str.caseUpper()
str.uppercase()
16.
What does the `String.charAt()` method return if the index is out of range?
`null`
An empty string
`undefined`
An error is thrown
17.
How do you convert a number to a string with a specific number of decimal places in JavaScript?
num.toString(2)
num.toFixed(2)
num.toPrecision(2)
String.format(num, 2)
18.
What is the purpose of the `Object.is()` function in JavaScript?
Returns a boolean indicating whether an object is frozen
Compares two values for equality, including handling special values such as NaN
Compares two values for equality, excluding handling special values such as NaN
Checks if an object is an instance of a specific class
19.
How do you convert a string to an array of characters in JavaScript?
Array.from(str)
str.toArray()
str.split('')
str.toCharArray()
20.
What is the purpose of the `String.link()` method in JavaScript?
Encodes a URI component
Creates an HTML anchor element with the specified URL
Converts a string to lowercase
Trims whitespace from both ends of a string