Question : What is JavaScript primarily used for?
Styling web pages
Server-side scripting
Enhancing user interfaces in web browsers
Database management
Correct Answer : Enhancing user interfaces in web browsers
Question : Which keyword is used to declare a variable in JavaScript?
v
var
variable
int
Correct Answer : var
Question : What will be the result of the following expression: 3 + '3'?
6
'33'
33
Error
Correct Answer : '33'
Question : Which of the following is not a data type in JavaScript?
String
Boolean
Float
Character
Correct Answer : Character
Question : What does the === operator do in JavaScript?
Assignment
Equality (strict comparison)
Inequality
Type coercion
Correct Answer : Equality (strict comparison)
Question : Which function is used to print output in the console in JavaScript?
print()
log()
display()
console()
Correct Answer : log()
Question : What is the purpose of the querySelector method in JavaScript?
Selects the first element that matches a specified CSS selector
Changes the document's URL
Adds a new HTML element
Converts a string to a number
Correct Answer : Selects the first element that matches a specified CSS selector
Question : Which of the following is a loop structure in JavaScript?
repeat
for/in
sequence
until
Correct Answer : for/in
Question : What does the this keyword refer to in JavaScript?
The current file
The calling function
The global object
The previous variable
Correct Answer : The global object
Question : Which event is triggered when a user clicks on an HTML element in JavaScript?
onhover
onsubmit
onclick
onkeydown
Correct Answer : onclick
Question : What is the purpose of the localStorage object in JavaScript?
Storing session-specific data
Storing data locally in the browser
Managing cookies
Accessing the server's file system
Correct Answer : Storing data locally in the browser
Question : Which keyword is used to prevent the execution of code in JavaScript?
prevent
stop
break
debugger
Correct Answer : debugger
Question : What is the result of the following code snippet: console.log(typeof (5 + '5'))?
number
string
NaN
undefined
Correct Answer : string
Question : What is the purpose of the JSON.stringify() method in JavaScript?
Parsing JSON data
Converting a JavaScript object to a JSON string
Retrieving data from an API
Creating a JSON object
Correct Answer : Converting a JavaScript object to a JSON string
Question : Which function is used to create a new element in the DOM in JavaScript?
createElement()
appendChild()
newElement()
addElement()
Correct Answer : createElement()
Question : What is the purpose of the Promise object in JavaScript?
To handle synchronous operations
To represent a value that might be available now, later, or never
To handle errors in asynchronous code
To create anonymous functions
Correct Answer : To represent a value that might be available now, later, or never
Question : What does the typeof operator return for null in JavaScript?
null
object
undefined
number
Correct Answer : object
Question : Which built-in object is used to handle errors in JavaScript?
Error
Exception
ErrorHandler
TryCatch
Correct Answer : Error
Question : What is the purpose of the splice() method in JavaScript?
To remove elements from an array
To add elements to the beginning of an array
To concatenate two arrays
To reverse the order of elements in an array
Correct Answer : To remove elements from an array
Question : Which keyword is used to declare a constant variable in JavaScript?
let
constant
const
var
Correct Answer : const
Question : What is the purpose of the addEventListener method in JavaScript?
To create event listeners for HTML elements
To add attributes to HTML elements
To create new elements in the DOM
To define functions in JavaScript
Correct Answer : To create event listeners for HTML elements
Question : Which of the following statements is true about the 'let' keyword in JavaScript?
It declares a variable with block scope
It declares a variable with function scope
It declares a constant variable
It is used to define a loop
Correct Answer : It declares a variable with block scope
Question : What does the isNaN() function in JavaScript do?
Checks if a value is not a number
Converts a value to a number
Checks if a value is negative
Retrieves the index of an array element
Correct Answer : Checks if a value is not a number
Question : Which of the following is used to iterate over the values of an iterable object in JavaScript?
for loop
forEach loop
while loop
do-while loop
Correct Answer : forEach loop
Question : What does the 'async' keyword do in a function declaration in JavaScript?
Declares a function as asynchronous
Declares a function as anonymous
Defines a function as an arrow function
Indicates a function with a return value
Correct Answer : Declares a function as asynchronous
Question : Which method is used to remove the last element from an array in JavaScript?
pop()
shift()
removeLast()
deleteLast()
Correct Answer : pop()
Question : What is the purpose of the 'bind()' method in JavaScript?
To bind HTML elements to a JavaScript function
To concatenate strings
To bind the value of 'this' in a function
To create a new array
Correct Answer : To bind the value of 'this' in a function
Question : What does the localStorage.removeItem() method do in JavaScript?
Adds a new item to localStorage
Updates an existing item in localStorage
Removes an item from localStorage
Clears all items from localStorage
Correct Answer : Removes an item from localStorage
Question : Which JavaScript method is used to join elements of an array into a string?
concat()
join()
merge()
combine()
Correct Answer : join()
Question : What does the 'arguments' object in a JavaScript function represent?
All parameters passed to the function
The function's return value
The function's local variables
The number of times the function is called
Correct Answer : All parameters passed to the function
Question : Which of the following is true about the 'map()' method in JavaScript?
It modifies the original array
It creates a new array by applying a function to each element
It removes elements from an array
It returns a boolean value
Correct Answer : It creates a new array by applying a function to each element
Question : What is the purpose of the 'typeof' operator in JavaScript?
To check if a variable is defined
To determine the type of a variable
To convert a string to a number
To create a new variable
Correct Answer : To determine the type of a variable
Question : In JavaScript, how do you create a new object using the Object constructor?
var obj = Object.new();
var obj = new Object();
var obj = create Object();
var obj = {}
Correct Answer : var obj = new Object();
Question : What is the purpose of the 'querySelectorAll' method in JavaScript?
Selects the first element that matches a specified CSS selector
Selects all elements that match a specified CSS selector
Removes all elements from the DOM
Adds a new HTML element
Correct Answer : Selects all elements that match a specified CSS selector
Question : Which JavaScript function is used to parse a JSON string?
parseJSON()
stringify()
JSON.parse()
JSON.stringify()
Correct Answer : JSON.parse()
Question : What is the purpose of the 'Object.keys()' method in JavaScript?
Returns an array of an object's enumerable property names
Returns an array of an object's values
Removes all properties from an object
Adds a new property to an object
Correct Answer : Returns an array of an object's enumerable property names
Question : Which statement is used to exit a loop prematurely in JavaScript?
stop
exit
break
end
Correct Answer : break
Question : What is the purpose of the 'Array.isArray()' method in JavaScript?
Checks if an array is empty
Checks if a variable is an array
Adds elements to an array
Concatenates two arrays
Correct Answer : Checks if a variable is an array
Question : Which of the following is not a valid way to declare a function in JavaScript?
function myFunction(){}
const myFunction = function(){}
var myFunction = () => {}
myFunction = function(){}
Correct Answer : myFunction = function(){}
Question : What is the purpose of the 'Array.reduce()' method in JavaScript?
Adds elements to the end of an array
Removes the first element from an array
Applies a function against an accumulator and each element in the array
Reverses the order of elements in an array
Correct Answer : Applies a function against an accumulator and each element in the array
No comments:
Post a Comment