NEW
Font size
WorksheetsQuiz For JavaScript
Total questions: 50
Worksheet time: 25mins
What is JavaScript primarily used for?
a. Creating desktop applications
B. Creating backend applications
c. Creating dynamic web pages
d. Handling 3D graphics
In which environment does JavaScript run?
a. Browser
b. Server
c. Both a and b
d. None of the above
Which command is used to print to the console in JavaScript?
a. print()
b. console.log()
c. echo()
d. document.write()
Which keyword is used to declare a variable in JavaScript?
a. var
b. let
c. const
d. All of the above
What is the difference between == and === in JavaScript?
a) == compares values and data types, while === compares only values
b) == compares values after type coercion, while === compares both values and data types without type coercion.
c) == is used for assignment, while === is used for comparison.
d) There is no difference; both == and === work the same way.
Can a variable declared with const change its value?
Yes
No
What happens if you access an undeclared variable?
a. undefined
b. Throws an error
c. null
d. An empty string
What is the result of the following code?
var a = 5;
let b = 10;
const c;
a. Variables a, b, and c are all valid
b. Error at variable c
c. a and b are invalid
d. The program runs without error
What is the result of the following code?
console.log(y);
a. undefined
b. Throws an error
c. null
d. An empty string
What is the result of the following code?
const x = 10;
x = 20;
console.log(x);
a. 20
b. 10
c. Throws an error
d. undefined
What is the difference between null and undefined?
a. null represents an absence of value, while undefined means a variable is declared but not assigned.
b. Both are identical.
c. null is an object, but undefined is a string.
d. null means not initialized, undefined is a mistake.
What is the result of typeof null and typeof undefined?
a. "null" and "undefined"
b. "object" and "undefined"
c. "undefined" and "null"
d. Throws an error
What is the type of NaN?
a. "undefined"
b. "number"
c. "NaN"
d. Throws an error
What is the purpose of the isNaN() function?
a. Check if a value is a number
b. Check if a value is not a number
c. Check if a string is valid
d. None of the above
What is the result of parseInt("20.9")?
a. 20.9
b. 20
c. NaN
d. undefined
What is the return value of Math.floor(4.7)?
a. 5
b. 4
c. 4.7
d. NaN
What is the result of String(123) + 456?
a. 579
b. "123456"
c. 123456
d. Throws an error
Which command returns the current time?
What is the result of the following code?
let str = "Hello";
console.log(str.length);
a. 4
b. 5
c. undefined
d. Throws an error
Which method is used to check if a string starts with a specific character?
a. startsWith()
b. includes()
c. indexOf()
d. substring()
What is the result of "JavaScript".toUpperCase()?
a. "javascript"
b. "JAVASCRIPT"
c. "JavaScript"
d. Throws an error
Which command is used to slice a string from position 2 to 5?
a. str.substring(2, 5)
b. str.slice(2, 5)
c. Both of the above
d. None of the above
Which method returns the first occurrence position of a substring?
a. lastIndexOf()
b. indexOf()
c. find()
d. search()
What is the result of Number("100") + 50 + true?
a. 150 + 1
b. "10051"
c. NaN
d. Throws an error
Which command converts a number to a string?
a. toString()
b. parseInt()
c. Number()
d. join()
What is the result of Math.round(4.5)?
a. 4
b. 5
c. 4.5
d. NaN
Which function returns a random number between 0 and 1?
a. Math.random()
b. Math.floor()
c. Math.abs()
d. Math.ceil()
What is the result of Math.max(3, 5, 1)?
a. 3
b. 5
c. 1
d. undefined
Which method adds an element to the end of an array?
a. push()
b. pop()
c. shift()
d. unshift()
Does the map() method mutate the original array in JavaScript?
a) Yes, it modifies the original array by applying the callback function.
b) No, it creates a new array and does not modify the original array.
c) It only modifies the original array if the callback function returns a value.
d) It mutates the original array but only for objects, not primitive values.
Which method returns an array that is a concatenation of two arrays?
a. join()
b. concat()
c. splice()
d. slice()
What is the result of ["x", "y", "z"].indexOf("y")?
a. 0
b. 1
c. 2
d. -1
How do you select an HTML element by its ID?
a. document.getElementById()
b. document.querySelector()
c. document.getElementsByClassName()
d. Both a and b
Which function adds a click event to an element?
a. element.click()
b. element.addEventListener("click", ...)
c. element.onClick()
d. element.attachEvent()
Which command creates a new HTML element?
a. document.createElement()
b. document.append()
c. document.newElement()
d. document.createNode()
Which keyword is used to declare a function in JavaScript?
a. function
b. def
c. func
d. None of the above
What is the result of:
javascript
Sao chép mã
let add = (a, b) => a + b;
console.log(add(3, 7));
a. 10
b. 37
c. Error
d. None of the above
How to run a piece of code only once after a specific time interval in
a) setInterval()
b) setTimeout()
c) clearTimeout()
d) clearInterval()
What is the result of:
javascript
Sao chép mã
const arr = [1, 2, 3];
const result = arr.map(num => num * 2);
console.log(result);
a. [2, 4, 6]
b. [1, 2, 3]
c. [2, 2, 2]
d. Error
What is the correct method to run a piece of code after a specific time interval in JavaScript?
a) setInterval()
b) setTimeout()
c) clearTimeout()
d) runAfterTime()
Which keyword is used to copy all properties of one object into another?
a. Object.assign()
b. Object.copy()
c. Object.create()
d. Object.merge()
Which property returns the keys of an object?
a. Object.keys()
b. Object.values()
c. Object.entries()
d. None of the above
Which method prevents modification of an object?
a. Object.freeze()
b. Object.lock()
c. Object.seal()
d. None of the above
What is the result of delete obj.key?
a. Deletes the key and its corresponding value
b. Returns undefined
c. Error
d. None of the above
What is the result of the following code?
const users = {
name: "hune",
age: 19,
phone: 0123456789,
social: {
ticktok: "hune1209",
instagram: "hune1209",
facebook: "hune1209"
}
};
users.phone = "1";
console.log(users);
a. Error “Uncaught TypeError: Assignment to constant variable.”
b. undefined
c. {"name": "hune",
"age": 19,
"phone": "1",
"social":
{"ticktok": "hune1209",
"instagram": "hune1209",
"facebook": "hune1209"}
}
c. {"name": "hune",
"age": 19,
"phone": "0123456789",
"social":
{"ticktok": "hune1209",
"instagram": "hune1209",
"facebook": "hune1209"}
}
Which method checks if all elements in the array meet a condition?
a. filter()
b. map()
c. forEach()
d. reduce()
What is the result of:
const a = [1, 2, 3, 4, 5];
const b = ["6", 7, 8, 9, 10];
const c = [...a, ...b];
console.log(c);
a. [1, 2, 3, 4, 5, "6", 7, 8, 9, 10]
b. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
c. []
d. undefined
Which method pick the first letter of an string?
a. slice(0,1)
b. chatAt(0)
c. both a and b
d. none of answer
What is the result of the following code?
const cart = [
{ product: "Apple", quantity: 2, price: 3 },
{ product: "Banana", quantity: 5, price: 1 },
{ product: "Cherry", quantity: 7, price: 2 }
];
const totalQuantity = cart.reduce((total, item) => total + item.quantity, 0);
console.log(`Total product quantity: ${totalQuantity}`);
a. 14
b. 16
c. 3
d. Error
Which command returns an array with only unique values from an original array?
a. new Set([...arr])
b. Array.unique()
c. arr.filter()
d. None of the above
