JavaScript Quiz (Beginner) - All Questions
This JavaScript Beginner Quiz is perfect for learners starting their journey in JavaScript. It covers core syntax, basic concepts, and fundamental programming ideas commonly asked in beginner interviews and practice tests.
Question 1: What is JavaScript primarily used for?
- Styling web pages
- Structuring web content
- Adding interactivity to web pages
- Managing databases
Explanation: JavaScript is used to add dynamic behavior and interactivity to web pages.
Question 2: Which keyword is used to declare a variable?
Explanation: var is a keyword used to declare variables in JavaScript.
Question 3: Which symbol is used for single-line comments?
Explanation: // is used to write single-line comments.
Question 4: Which data type represents true or false?
- Number
- String
- Boolean
- Object
Explanation: Boolean values can be either true or false.
Question 5: How do you display a message in an alert box?
- alert('Hello')
- msg('Hello')
- console.alert('Hello')
- popup('Hello')
Explanation: alert() is used to show a popup alert box.
Question 6: Which operator assigns a value to a variable?
Explanation: The = operator assigns values.
Question 7: Which operator checks value and type?
Explanation: === compares both value and data type.
Question 8: What is the output of typeof 10?
Explanation: typeof 10 returns 'number'.
Question 9: Which keyword declares a constant?
Explanation: const declares a constant variable.
Question 10: Which method prints output to the console?
- print()
- log()
- console.log()
- write()
Explanation: console.log() outputs data to the console.
Question 11: Which brackets are used for arrays?
Explanation: Arrays are defined using square brackets.
Question 12: How do you access the first element of an array?
- arr(0)
- arr[1]
- arr[0]
- arr.first()
Explanation: Array indexing starts from 0.
Question 13: Which keyword is used to create a function?
Explanation: function keyword defines a function.
Question 14: How do you call a function named test?
- call test()
- test()
- run test
- execute(test)
Explanation: Functions are called using parentheses.
Question 15: Which loop runs at least once?
- for
- while
- do...while
- foreach
Explanation: do...while executes before condition checking.
Question 16: Which statement is used for decision making?
Explanation: if statement is used for conditional logic.
Question 17: Which value represents no value intentionally?
Explanation: null represents an intentional absence of value.
Question 18: Which value means a variable is declared but not assigned?
Explanation: undefined means no value has been assigned.
Question 19: Which method converts JSON to an object?
- JSON.stringify()
- JSON.parse()
- JSON.convert()
- JSON.object()
Explanation: JSON.parse() converts JSON string into an object.
Question 20: Which method converts an object to JSON?
- JSON.parse()
- JSON.object()
- JSON.stringify()
- JSON.encode()
Explanation: JSON.stringify() converts an object to JSON.
Question 21: What is JavaScript mainly used for?
- Styling web pages
- Structuring web content
- Adding interactivity to web pages
- Managing servers
Explanation: JavaScript adds interactivity and dynamic behavior to web pages.
Question 22: Which keyword is used to declare a variable?
Explanation: var is a keyword used to declare variables in JavaScript.
Question 23: Which symbol is used for single-line comments?
Explanation: // is used for single-line comments.
Question 24: Which data type stores true or false values?
- Number
- Boolean
- String
- Object
Explanation: Boolean values can be true or false.
Question 25: How do you display a message box in JavaScript?
- msg()
- alert()
- prompt()
- console.log()
Explanation: alert() displays a message box.
Question 26: Which operator assigns a value to a variable?
Explanation: The = operator assigns values.
Question 27: Which operator compares value and type?
Explanation: === compares both value and data type.
Question 28: What is the result of typeof "hello"?
Explanation: typeof returns 'string' for string values.
Question 29: Which keyword declares a constant?
Explanation: const declares a constant variable.
Question 30: Which function prints output to the console?
- print()
- log()
- console.log()
- write()
Explanation: console.log() outputs messages to the browser console.
Question 31: Which brackets are used to define an array?
Explanation: Arrays are defined using square brackets.
Question 32: What is the index of the first element in an array?
Explanation: Array indexing starts from 0.
Question 33: Which keyword is used to create a function?
Explanation: The function keyword defines a function.
Question 34: How do you call a function named demo?
- call demo()
- demo()
- run demo()
- execute(demo)
Explanation: Functions are called using parentheses.
Question 35: Which loop runs at least once?
- for
- while
- do...while
- foreach
Explanation: do...while executes the code before checking the condition.
Question 36: Which statement is used for decision making?
Explanation: if is used for conditional logic.
Question 37: Which value represents intentional absence of value?
Explanation: null represents an intentional empty value.
Question 38: Which value means a variable has no assigned value?
Explanation: undefined means no value has been assigned.
Question 39: Which method adds an element to the end of an array?
- push()
- pop()
- shift()
- unshift()
Explanation: push() adds an element to the end of an array.
Question 40: Which method removes the last element from an array?
- shift()
- remove()
- slice()
- pop()
Explanation: pop() removes the last element.
Question 41: Which event occurs when a button is clicked?
- onhover
- onload
- onclick
- onchange
Explanation: onclick fires when an element is clicked.
Question 42: Which object represents the browser window?
- document
- window
- browser
- screen
Explanation: window is the global browser object.
Question 43: Which method selects an element by ID?
- querySelector()
- getElement()
- getElementById()
- selectId()
Explanation: getElementById() selects elements by ID.
Question 44: Which keyword refers to the current object?
Explanation: this refers to the current execution context.
Question 45: Which error occurs due to incorrect syntax?
- Runtime error
- Logic error
- Syntax error
- Type error
Explanation: Syntax errors occur when code structure is invalid.
Question 46: Which operator is used for addition?
Explanation: + adds values.
Question 47: Which keyword stops a loop execution?
Explanation: break exits the loop.
Question 48: Which keyword skips the current loop iteration?
Explanation: continue skips the current iteration.
Question 49: Which method converts JSON string to object?
- JSON.stringify()
- JSON.parse()
- JSON.convert()
- JSON.object()
Explanation: JSON.parse() converts JSON to object.
Question 50: Which method converts object to JSON string?
- JSON.stringify()
- JSON.parse()
- JSON.encode()
- JSON.objectify()
Explanation: JSON.stringify() converts object to JSON.
Question 51: Which keyword declares a block-scoped variable?
Explanation: let declares block-scoped variables.
Question 52: Which operator represents logical AND?
Explanation: && is the logical AND operator.
Question 53: What does NaN stand for?
- No assigned Number
- Not a Number
- Negative Number
- New assigned Number
Explanation: NaN means Not a Number.
Question 54: Which function executes code after a delay?
- setInterval()
- wait()
- delay()
- setTimeout()
Explanation: setTimeout() runs code after a delay.
Question 55: Which function repeats execution at intervals?
- setTimeout()
- repeat()
- loop()
- setInterval()
Explanation: setInterval() executes code repeatedly.
Question 56: Which method joins array elements into a string?
- concat()
- merge()
- join()
- combine()
Explanation: join() combines array elements into a string.
Question 57: Which operator increments a value by one?
Explanation: ++ increases a value by one.
Question 58: Which statement is used inside switch cases?
Explanation: break exits a switch case.
Question 59: Which built-in object handles dates?
Explanation: Date object handles date and time.
Question 60: Which property gives the length of a string?
- size()
- count()
- length
- length()
Explanation: length property returns string length.
Question 61: Which operator represents logical OR?
Explanation: || represents logical OR.
Question 62: Which value is returned by a function without return?
Explanation: Functions return undefined by default.
Question 63: Which method converts a number to a string?
- toString()
- String()
- Both A and B
- convert()
Explanation: Both toString() and String() convert numbers to strings.
Question 64: Which operator checks inequality?
Explanation: != and !== both check inequality.
Question 65: Which symbol is used in arrow functions?
Explanation: => is used to define arrow functions.
Question 66: Which JavaScript feature allows code reuse?
- Loops
- Conditions
- Functions
- Variables
Explanation: Functions allow reusable code blocks.