General JS II
1.
Which keyword is used to declare a block-scoped variable in JavaScript?
var
const
let
block
2.
What is the purpose of the `event.stopPropagation()` method in JavaScript?
Prevents the default action of the event
Stops the event from bubbling up the DOM tree
Stops the event propagation to the parent elements
Disables the event completely
3.
What is the difference between `null` and `undefined` in JavaScript?
`null` is a primitive value, and `undefined` is an object
`null` is an object, and `undefined` is a primitive value
Both represent the absence of value
They are completely interchangeable
4.
What does the `===` operator do in JavaScript?
Compares values for equality with type coercion
Compares values for equality without type coercion
Performs strict type coercion
Assigns a value to a variable
5.
How do you convert a string to lowercase in JavaScript?
str.toLower()
str.uppercase()
str.toLowerCase()
str.caseLower()
6.
Which of the following is a correct way to create an object in JavaScript?
var obj = new Object();
var obj = {}
var obj = Object.create();
var obj = new {}
7.
What is the purpose of the `Array.map()` method in JavaScript?
Modifies the original array by applying a function to each element
Creates a new array by applying a function to each element of the original array
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
8.
How would you check if a variable is a number in JavaScript?
if (x instanceof Number)
if (x.isNumber())
if (typeof x === 'number')
if (x.type === 'number')
9.
What is the purpose of the `Array.filter()` method in JavaScript?
Modifies the original array by applying a function to each element
Creates a new array by applying a function to each element of the original array
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
10.
How do you concatenate two arrays in JavaScript?
arr1 + arr2
arr1.concat(arr2)
arr1.join(arr2)
arr1.combine(arr2)
11.
What is the purpose of the `Array.reduce()` method in JavaScript?
Modifies the original array by applying a function to each element
Creates a new array by applying a function to each element of the original array
Filters the elements of an array based on a given condition
Reduces the array to a single value by applying a function
12.
What is the purpose of the `Object.keys()` method in JavaScript?
Returns an array of a given object's keys and values
Returns an array of a given object's own and inherited property names
Returns an array of a given object's values
Returns an array of a given object's own enumerable property names
13.
How do you check if a number is an integer in JavaScript?
x % 1 === 0
x.isInteger()
typeof x === 'integer'
Number.isInteger(x)
14.
What is the purpose of the `Array.unshift()` method in JavaScript?
Adds one or more elements to the end of an array and returns the new length
Removes the last element from an array and returns that element
Adds one or more elements to the beginning of an array and returns the new length
Removes the first element from an array and returns that element
15.
How do you check if a string contains a specific substring in JavaScript?
str.contains('substring')
str.includes('substring')
str.hasSubstring('substring')
str.indexOf('substring') !== -1
16.
What is the purpose of the `Object.freeze()` method in JavaScript?
Prevents new properties from being added to an object
Prevents an object from being modified
Prevents an object from being deleted
Prevents an object from being created
17.
How do you round a number down to the nearest integer in JavaScript?
Math.round(x)
Math.floor(x)
Math.ceil(x)
roundDown(x)
18.
What is the purpose of the `Array.slice()` method in JavaScript?
Adds one or more elements to the end of an array and returns the new length
Removes the last element from an array and returns that element
Returns a shallow copy of a portion of an array into a new array object
Removes the first element from an array and returns that element
19.
How do you convert a number to a string in JavaScript?
str.convertToString()
str.toString()
String(x)
x.string()
20.
How do you convert a string to an integer in JavaScript?
Number(str)
str.toInteger()
str.convertToInteger()
parseInt(str)