General JS X
1.
How do you declare a variable with block scope in JavaScript?
const x = 10;
var x = 10;
let x = 10;
block x = 10;
2.
What is the purpose of the `Math.abs()` function in JavaScript?
Returns the natural logarithm of a number
Returns the square root of a number
Returns the absolute value of a number
Rounds a number to the nearest integer
3.
How do you check if a variable is a string in JavaScript?
myVar.type === 'string'
myVar.isString()
typeof myVar === 'string'
myVar instanceof String
4.
What is the purpose of the `String.fontcolor()` method in JavaScript?
Encodes HTML entities
Changes the color of the text in a string
Converts a string to uppercase
Trims whitespace from both ends of a string
5.
How do you convert a string to a number in JavaScript?
parseInt(str)
Number(str)
str.toNumber()
parseFloat(str)
6.
What is the purpose of the `String.italics()` method in JavaScript?
Encodes HTML entities
Creates an HTML italic element
Converts a string to uppercase
Trims whitespace from both ends of a string
7.
How do you declare a variable with a constant value in JavaScript?
x.const(42);
let x = 42;
var x = 42;
const x = 42;
8.
What is the purpose of the `Number.isFinite()` method in JavaScript?
Returns the square root of a number
Determines whether a value is a finite number
Converts a value to NaN
Checks if a variable is of type Number
9.
How do you declare a function in JavaScript?
let myFunction = () => {}
const myFunction = function() {}
function myFunction() {}
myFunction = function() {}
10.
What does the `String.strike()` method do in JavaScript?
Converts a string to lowercase
Encodes HTML entities
Creates an HTML strikethrough element
Trims whitespace from both ends of a string
11.
How do you declare a variable with a dynamic type in JavaScript?
var x;
let x = 42;
const x = 42;
var x = 42;
12.
What is the purpose of the `Math.random()` function in JavaScript?
Generates a random floating-point number between 0 (inclusive) and 1 (exclusive)
Returns the square root of a number
Returns the natural logarithm of a number
Rounds a number to the nearest integer
13.
How do you check if a number is even in JavaScript?
if (num % 2)
if (num.isEven())
num.isEven()
num % 2 === 0
14.
What is the purpose of the `String.underline()` method in JavaScript?
Encodes HTML entities
Creates an HTML underline element
Converts a string to lowercase
Trims whitespace from both ends of a string
15.
How do you round a number to the nearest integer in JavaScript?
Math.ceil(x)
Math.floor(x)
Math.round(x)
round(x)
16.
What does the `Number.NaN` property represent in JavaScript?
The square root of -1
A value representing Not-a-Number
Infinity
The value undefined
17.
How do you check if a string is empty in JavaScript?
str.isEmpty()
str.length === 0
if (str === '')
if (str) { /* code */ }
18.
What is the purpose of the `Date.toISOString()` method in JavaScript?
Returns the number of milliseconds since January 1, 1970, 00:00:00 UTC
Returns the current date and time in the local time zone
Returns a string representing a date and time in UTC format
Converts a date to a string in the specified format
19.
How do you check if a variable is null in JavaScript?
if (myVar === null)
if (myVar.isNull())
if (myVar === undefined)
if (myVar.isUndefined())
20.
What is the purpose of the `String.fromCharCode()` method in JavaScript?
Reverses the order of characters in a string
Returns a string created by using the specified sequence of Unicode values
Converts a string to lowercase
Trims whitespace from both ends of a string