JavaScript MCQs – Class 12 Web Applications (803) | CBSE Full revision
These JavaScript MCQs are specially designed for CBSE Class 12 Web Application (803) students. Based on the latest CBSE syllabus and exam pattern, these questions help you strengthen your concepts, understand important JavaScript topics, and prepare effectively to score full marks in your exam.
Q1. JavaScript was developed in 1995 by:
a) Tim Berners-Lee
b) Brendan Eich
c) Dennis Ritchie
d) James Gosling
Q2. JavaScript code is executed by a/an:
a) Compiler
b) Interpreter
c) Assembler
d) Translator only
Q3. JavaScript code can be implemented in HTML using:
a) <js> tags
b) <javascript> tags
c) <script>…</script> tags
d) <code>…</code> tags
Q4. An external JavaScript file must have the extension:
a) .html
b) .css
c) .js
d) .java
Q5. Which of the following is NOT listed as an advantage of JavaScript?
a) It is relatively easy to learn and use
b) It works only on the server side
c) It is supported by all browsers
d) It provides dynamism and interactivity
Q6. Which pair correctly represents the two broad categories of JavaScript data types discussed?
a) Numeric and textual
b) Primitive and Non-Primitive
c) Static and Dynamic
d) Local and Global
Q7. Which of the following is a primitive data type?
a) Object
b) Array
c) Function
d) Boolean
Q8. Which of the following is a non-primitive data type?
a) String
b) Number
c) Array
d) Boolean
Q9. What is the output type of typeof(25/0)?
a) Infinity
b) Undefined
c) Number
d) NaN
Q10. Which expression produces NaN according to the given concept?
a) 20/0
b) ‘hello’ * 4
c) 15+5
d) 30/5
Q11. What is the result of typeof(NaN)?
a) NaN
b) Undefined
c) String
d) Number
Q12. What will var a; document.write(a); display?
a) null
b) 0
c) undefined
d) false
Q13. A local variable is visible:
a) Everywhere in the program
b) Only within the function where it is defined
c) Only in the HTML head
d) Only on the web page body
Q14. A variable defined anywhere in JavaScript code and having global scope is called a:
a) Local variable
b) Function variable
c) Global variable
d) Temporary variable
Q15. A function parameter is:
a) Always global
b) Always local to that function
c) Always an object
d) Always a string
Q16. What is the value of 20 % 10?
a) 0
b) 2
c) 10
d) 20
Q17. Which operator increases an integer value by one?
a) —
b) ++
c) +=
d) **
Q18. Which operator is used to raise one value to the power of another?
a) ^
b) //
c) **
d) ^^
Q19. If a = 15 and b = 25, the result of (a == b) is:
a) true
b) false
c) NaN
d) undefined
Q20. If a = 15 and b = 25, the result of (a < b) is:
a) true
b) false
c) 0
d) undefined
Q21. According to the logical AND rule described in the text, (5 && 15) outputs:
a) 5
b) 15
c) true
d) false
Q22. According to the logical OR rule described in the text, (8 || 18) outputs:
a) 8
b) 18
c) true
d) false
Q23. The expression !(12 > 10 && 4 > 7) evaluates to:
a) true
b) false
c) NaN
d) 0
Q24. The statement total += marks is equivalent to:
a) total = marks
b) total = total + marks
c) total = marks + marks
d) total = total – marks
Q25. The conditional operator is also called the:
a) Binary operator
b) Unary operator
c) Ternary operator
d) Logical operator
Q26. Which operator is used to determine the data type of an operand?
a) type
b) typeof
c) datatype
d) checktype
Q27. The correct syntax of the conditional operator is:
a) Condition ; First : Second
b) Condition ? First : Second
c) Condition : First ? Second
d) First ? Condition : Second
Q28. A collection of statements that carries out an operation or calculates a value is called a:
a) Object
b) JavaScript function
c) Array
d) Literal
Q29. The main advantage of a function is that:
a) It can be defined once and used many times
b) It can only be executed once
c) It cannot receive input
d) It cannot return a value
Q30. The code to be executed by a function is enclosed within:
a) Parentheses
b) Curly brackets
c) Square brackets
d) Angle brackets
Q31. Which of the following is a valid function name?
a) 456Total()
b) change Name()
c) calculateSum()
d) function()
Q32. Which of the following is an invalid function name?
a) displayResult()
b) calculateTotal()
c) 7Marks()
d) showStudent()
Q33. A webpage needs to accept a user’s name as input. Which built-in JavaScript function should be used?
a) alert()
b) prompt()
c) parseFloat()
d) isNaN()
Q34. Which built-in function converts a value to an integer?
a) parseInt()
b) parseFloat()
c) prompt()
d) alert()
Q35. Which function displays a message in a box on the window?
a) prompt()
b) alert()
c) message()
d) display()
Q36. The return statement in a function:
a) Loops the function repeatedly
b) Terminates the function and sends a value back to the caller
c) Declares a new variable
d) Deletes the function
Q37. Which notation is used to access an object property?
a) object[property] only
b) object.property
c) object->property
d) object:property
Q38. In a string, indexing starts from:
a) 1
b) -1
c) 0
d) 10
Q39. The only String property specifically mentioned in the syllabus is:
a) size
b) count
c) length
d) index
Q40. Which string method does NOT accept negative indexes?
a) slice()
b) substring()
c) replace()
d) concat()
Q41. A variable msg contains the string “I like Java”. Which statement will change the first occurrence of “Java” to “Python”?
a) msg.replace(“Java”,”Python”)
b) msg.replaceAll(“Java”,”Python”)
c) msg.slice(“Java”,”Python”)
d) msg.match(“Java”,”Python”)
Q42. A student has stored “web application” in the variable title. Which statement will convert the complete string into uppercase?
a) title.upper()
b) title.toUpperCase()
c) title.uppercase()
d) title.makeUpper()
Q43. A user enters ” JavaScript ” in a text field. Which statement will remove the whitespace from both the beginning and end of the string?
a) name.remove()
b) name.trim()
c) name.strip()
d) name.clearSpace()
Q44. Consider the following code: var subject = “Computer”; Which statement will return the character at index 3?
a) subject.char(3)
b) subject.character(3)
c) subject.charAt(3)
d) subject.indexChar(3)
Q45. Which of these correctly creates an array using an array literal?
a) var arr = (1,2,3)
b) var arr = {1,2,3}
c) var arr = [1,2,3]
d) var arr = new [1,2,3]
Q46. Which keyword, along with Array( ), is used to create an array using a constructor?
a) create
b) new
c) make
d) build
Q47. The last element of an array can be accessed using:
a) array[0]
b) array[length]
c) array[array.length-1]
d) array[length+1]
Q48. Consider the following array: var subjects = [“English”, “Math”, “Computer”]; Which statement will remove “Computer” from the end of the array?
a) subjects.shift()
b) subjects.pop()
c) subjects.push()
d) subjects.removeLast()
Q49. Consider the following array: var subjects = [“English”, “Math”]; Which statement will add “Computer” at the end of the array?
a) subjects.push(“Computer”)
b) subjects.pop(“Computer”)
c) subjects.unshift(“Computer”)
d) subjects.append(“Computer”)
Q50. Consider the following array: var colors = [“Red”, “Green”, “Blue”]; Which statement will remove “Red” from the beginning of the array?
a) colors.pop()
b) colors.shift()
c) colors.removeFirst()
d) delete colors[0]
Q51. Consider the following array: var colors = [“Red”, “Green”, “Blue”]; Which statement will add “Yellow” at the beginning of the array?
a) colors.push(“Yellow”)
b) colors.shift(“Yellow”)
c) colors.unshift(“Yellow”)
d) colors.prepend(“Yellow”)
Q52. Consider the following array: var subjects = [“English”, “Math”, “Computer”]; Which statement will display the elements as a single string separated by ” – “?
a) subjects.concat(” – “)
b) subjects.join(” – “)
c) subjects.toString(” – “)
d) subjects.merge(” – “)
Q53. Consider the following array: var numbers = [10, 20, 30, 40]; Which statement will reverse the order of elements in the original array?
a) numbers.slice()
b) numbers.concat()
c) numbers.reverse()
d) numbers.join()
Q54. By default, JavaScript’s sort() method sorts array values as:
a) Numbers only
b) Strings in alphabetical/ascending order
c) Numbers in descending order
d) Random values
Q55. A programmer has written a calculation that must be performed repeatedly with different input values. Which approach best matches the concept taught in the chapter?
a) Repeat the entire code manually
b) Create a function and call it multiple times
c) Store every result in an object
d) Use only an array
Q56. A student writes a function with two parameters but calls it without supplying the required values. Based on the chapter’s example, what can happen to the output of the calculation?
a) It will always be 0
b) It will produce NaN
c) It will always be true
d) It will produce null
Q57. A developer needs the greatest integer less than or equal to 8.9. Which method should be used?
a) Math.ceil()
b) Math.round()
c) Math.floor()
d) Math.max()
Q58. A website needs to generate a random floating-point value from 0 up to but not including 1. Which method should be selected?
a) Math.random()
b) Math.round()
c) Math.sqrt()
d) Math.pow()
Q59. What will be the output? document.write(Math.round(5.49));
a) 5
b) 6
c) 5.49
d) 0
Q60. What will be the output? document.write(Math.ceil(5.1));
a) 5
b) 6
c) 5.1
d) 0
Q61. Assertion (A): JavaScript is called an interpreted language.
Reason (R): The interpreter executes JavaScript code line by line.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Q62. Assertion (A): NaN has the data type number according to the chapter.
Reason (R): typeof(NaN) returns number.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Q63. Assertion (A): A local variable is visible throughout the JavaScript program.
Reason (R): A local variable is visible only within the function where it is defined.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true