JavaScript Basics Quiz
A beginner-friendly quiz to evaluate your understanding of core JavaScript fundamentals including variables, data types, operators, and foundational syntax. This quiz builds the base for mastering more advanced JavaScript concepts.
Question 1
What is the output of the following code?
console.log(typeof undefined)Question 2
Which of the following declares a block-scoped variable?
Question 3
What will the following expression return?
"5" === 5Question 4
What is the output of the following code?
console.log(2 + "3")Question 5
Which statement best describes JavaScript?
Question 6
Which keyword declares a constant variable that cannot be reassigned?
Question 7
How do you write a template literal that outputs “Hello, John!” when name is “John”?
const name = "John"
// Fill the blank
const message = `Hello, ${_____}!`Question 8
What is the default value of a variable declared with let but not assigned?
Question 9
Which array method creates a new array with results of calling a provided function on every element?
Question 10
What will be logged?
const obj = { a: 1 }
const copy = obj
copy.a = 2
console.log(obj.a)Question 11
Which of these values is falsy in JavaScript?
Question 12
Which statement properly checks if `person.age` exists before accessing it?
Question 13
What will `Array.isArray([])` return?
Question 14
How do you convert the string "42" to a number using shorthand syntax?
Question 15
Which keyword is used to create a block scope?
Question 16
What is the output of the following arrow function?
const add = (a, b) => a + b
console.log(add(2, 3))Question 17
Which method converts a JSON string into an object?
Question 18
What does the spread operator do in the following context?
const arr = [1, 2, 3]
const copy = [...arr]Question 19
What will be logged?
console.log(1 == "1")Question 20
What is the result of `typeof NaN`?
Question 21
How do you check if an array includes a specific value?
Question 22
What does the `trim()` method do on a string?
Question 23
Which pattern describes an immediately invoked function expression?
Question 24
What will this code log?
const arr = [1, 2, 3]
arr.push(4)
console.log(arr.length)Question 25
Which statement about strict mode is true?
Question 26
How do you create a Promise that resolves immediately with value 5?
Question 27
What is logged?
let x
console.log(x === undefined)Question 28
Which loop is best for iterating over object keys?
Question 29
How do you declare a default parameter in a function?
function greet(name = "Guest") {
return `Hello, ${name}!`
}Question 30
What is the purpose of the `finally` block in a try/catch?
Question 31
What does `document.querySelector(".button")` return?
Question 32
Which operator is used for nullish coalescing?
Question 33
What will this log?
const value = "5"
console.log(value * 2)Question 34
Which method removes the last element from an array and returns it?
Question 35
What is the result of `[1, 2, 3].includes(2)`?
Question 36
Which statement about `setTimeout` is correct?
Question 37
What danger exists when comparing objects directly with `===`?
Question 38
What is the correct way to destructure the `name` property from an object?
const user = { name: "Ada", age: 30 }
// Fill the blank
const { _____ } = userQuestion 39
Which statement properly creates a class with a constructor?
class Person {
constructor(name) {
this.name = name
}
}Question 40
What will be logged?
const numbers = [1, 2, 3]
const [first, ...rest] = numbers
console.log(rest)