Don't forget to hit the ⭐ if you like this repo.
You must place your answer file in the submission folder. Within the submission/Q1/set_b
folder, create a folder called your github_id
.
-
Which keyword is used to declare a variable in JavaScript?
- a)
var
- b)
let
- c)
const
- d) All of the above
- a)
-
What is the correct way to comment a single line of code in JavaScript?
- a)
/* Comment */
- b)
<!-- Comment -->
- c)
// Comment
- d)
# Comment
- a)
-
What is the output of the following code snippet?
console.log(2 + "2");
- a)
4
- b)
"4"
- c)
22
- d)
NaN
- a)
-
Which data type represents a sequence of characters in JavaScript?
- a) String
- b) Number
- c) Boolean
- d) Object
-
How do you declare a constant variable in JavaScript?
- a)
var
- b)
let
- c)
const
- d)
constant
- a)
-
What is the output of the following code snippet?
console.log(10 > 5 && 5 < 3);
- a)
true
- b)
false
- c)
NaN
- d)
SyntaxError
- a)
-
How do you define a function in JavaScript?
- a)
func myFunction() {}
- b)
function: myFunction() {}
- c)
function myFunction() {}
- d)
def myFunction() {}
- a)
-
What is the purpose of the
addEventListener
method in JavaScript?- a) To add comments to the code
- b) To execute a function when an event occurs
- c) To modify the style of an element
- d) To declare a variable
-
What is the output of the following code snippet?
var x = 5; console.log(x++);
- a)
5
- b)
6
- c)
4
- d)
NaN
- a)
-
Which JavaScript keyword is used to exit a loop iteration?
- a)
exit
- b)
continue
- c)
break
- d)
return
- a)
-
What does the acronym "DOM" stand for in JavaScript?
- a) Document Object Model
- b) Data Object Model
- c) Dynamic Object Model
- d) Document Order Model
-
How do you select an HTML element using its
id
in JavaScript?- a)
selectElementById()
- b)
getElement()
- c)
querySelector()
- d)
getElementById()
- a)
-
What is the purpose of the
try...catch
statement in JavaScript?- a) To declare a new function
- b) To handle runtime errors
- c) To perform arithmetic operations
- d) To modify the DOM
-
What is the output of the following code snippet?
console.log(typeof undefined);
- a)
"undefined"
- b)
"null"
- c)
"boolean"
- d)
"number"
- a)
-
Which of the following is an example of a JavaScript library?
- a) React
- b) JavaFX
- c) Django
- d) Flask
-
What is the correct syntax to access a property of an object in JavaScript?
- a)
object.property
- b)
object[property]
- c)
object->property
- d)
object::property
- a)
-
What is the output of the following code snippet?
var arr = [1, 2, 3, 4, 5]; console.log(arr.length);
- a)
1
- b)
5
- c)
4
- d)
undefined
- a)
-
How do you convert a string to lowercase in JavaScript?
- a)
toLowerCase()
- b)
toLower()
- c)
lowerCase()
- d)
convertToLower()
- a)
-
Which method is used to add a new element at the end of an array in JavaScript?
- a)
push()
- b)
pop()
- c)
shift()
- d)
unshift()
- a)
-
What is the output of the following code snippet?
console.log(typeof NaN);
- a)
"number"
- b)
"undefined"
- c)
"NaN"
- d)
"string"
- a)
-
Which JavaScript method is used to remove the first occurrence of a specific element from an array?
- a)
shift()
- b)
splice()
- c)
slice()
- d)
remove()
- a)
-
What is the purpose of the
setTimeout
function in JavaScript?- a) To delay the execution of a function
- b) To change the style of an element
- c) To perform mathematical calculations
- d) To validate form inputs
-
What is the output of the following code snippet?
var x = 10; var y = "5"; console.log(x + y);
- a)
"105"
- b)
"15"
- c)
"NaN"
- d)
SyntaxError
- a)
-
Which event occurs when a user clicks on an HTML element?
- a)
onload
- b)
onchange
- c)
onclick
- d)
onmouseover
- a)
-
What is the purpose of the
innerHTML
property in JavaScript?- a) To change the HTML content of an element
- b) To add a new class to an element
- c) To select an element by its ID
- d) To execute a function when an event occurs
-
What is the output of the following code snippet?
var num = 10; console.log(num.toFixed(2));
- a)
10
- b)
10.00
- c)
NaN
- d)
SyntaxError
- a)
-
How do you check if a variable is an array in JavaScript?
- a)
Array.isArray(variable)
- b)
variable.isArray()
- c)
typeof variable === "array"
- d)
variable instanceof Array
- a)
-
What is the purpose of the
parseInt
function in JavaScript?- a) To convert a string to an integer
- b) To format a number with decimal places
- c) To calculate the square root of a number
- d) To sort elements in an array
-
What is the output of the following code snippet?
console.log("2" + 2);
- a)
4
- b)
"22"
- c)
2
- d)
"2"
- a)
-
Which method is used to remove the last element from an array in JavaScript?
- a)
push()
- b)
pop()
- c)
shift()
- d)
unshift()
- a)
-
What is the purpose of the
querySelector
method in JavaScript?- a) To select the first element that matches a CSS selector
- b) To add a new element to the DOM
- c) To remove an element from the DOM
- d) To modify the style of an element
-
What is the output of the following code snippet?
console.log(0.1 + 0.2 === 0.3);
- a)
true
- b)
false
- c)
NaN
- d)
SyntaxError
- a)
-
How do you access the length of an array in JavaScript?
- a)
array.length
- b)
array.size()
- c)
array.length()
- d)
array.size
- a)
-
What is the purpose of the
parseFloat
function in JavaScript?- a) To convert a string to a floating-point number
- b) To convert a number to a string
- c) To round a number to the nearest integer
- d) To calculate the square root of a number
-
What is the output of the following code snippet?
var x = 10; var y = 5; console.log(x += y);
- a)
5
- b)
10
- c)
15
- d)
SyntaxError
- a)
-
How do you create a new object in JavaScript?
- a)
new Object()
- b)
Object.create()
- c)
{}
- d) All of the above
- a)
-
What is the output of the following code snippet?
console.log(Boolean(""));
- a)
true
- b)
false
- c)
null
- d)
undefined
- a)
-
Which JavaScript method is used to remove the last element from an array?
- a)
shift()
- b)
splice()
- c)
slice()
- d)
pop()
- a)
-
What is the purpose of the
toUpperCase
method in JavaScript?- a) To convert a string to uppercase letters
- b) To convert a string to lowercase letters
- c) To split a string into an array of substrings
- d) To remove whitespace from the beginning and end of a string
-
What is the output of the following code snippet?
console.log(10 % 3);
- a)
3
- b)
1
- c)
0
- d)
10
- a)
-
How do you access the first element of an array in JavaScript?
- a)
array[0]
- b)
array.first()
- c)
array.getElement(0)
- d)
array.firstElement()
- a)
-
What is the purpose of the
split
method in JavaScript?- a) To convert a string to an array of substrings
- b) To join two or more arrays into one
- c) To merge two or more objects into one
- d) To split an element into multiple elements
-
What is the output of the following code snippet?
console.log(Math.floor(3.9));
- a)
3
- b)
4
- c)
3.9
- d)
SyntaxError
- a)
-
How do you remove an event listener in JavaScript?
- a)
removeEventListener()
- b)
detachEvent()
- c)
removeEvent()
- d)
unbindEvent()
- a)
-
What is the purpose of the
Math.random
method in JavaScript?- a) To generate a random number between 0 and 1
- b) To round a number to the nearest integer
- c) To calculate the square root of a number
- d) To calculate the absolute value of a number
-
What is the output of the following code snippet?
console.log(10 + "5");
- a)
15
- b)
"15"
- c)
105
- d)
SyntaxError
- a)
-
Which JavaScript method is used to concatenate two or more arrays?
- a)
concat()
- b)
push()
- c)
join()
- d)
merge()
- a)
-
What is the purpose of the
toFixed
method in JavaScript?- a) To format a number with a specified number of decimal places
- b) To convert a number to a string
- c) To check if a value is a number
- d) To calculate the square root of a number
-
What is the output of the following code snippet?
console.log(true && false);
- a)
true
- b)
false
- c)
NaN
- d)
SyntaxError
- a)
-
How do you access the value of a checkbox in JavaScript?
- a)
checkbox.value
- b)
checkbox.checked
- c)
checkbox.selected
- d)
checkbox.state
- a)
Please create an Issue for any improvements, suggestions or errors in the content.
You can also contact me using Linkedin for any other queries or feedback.