JavaScript Quiz - MCQ - Multiple Choice Questions
Q. What is the output of this code?
var num = 10; if (num < 5) { console.log("Less than 5"); } else if (num < 10) { console.log("Between 5 and 10"); } else { console.log("Greater than 10"); }A. Less than 5
B. Between 5 and 10
C. Greater than 10
D. The code has an error
Q. What will be the output of this code?
var x = 5; var y = "5"; console.log(x == y);A. true
B. false
C. Syntax error
D. undefined
Q. What is the output of this code?
var myArray = ["apple", "banana", "cherry"]; myArray.splice(1, 0, "date", "elderberry"); console.log(myArray);A. ["apple", "banana", "date", "elderberry", "cherry"]
B. ["apple", "date", "elderberry", "banana", "cherry"]
C. ["apple", "date", "banana", "elderberry", "cherry"]
D. ["apple", "banana", "cherry", "date", "elderberry"]
Q. What is the output of this code?
function greet(name) { return "Hello, " + name; } var greeting = greet("Alice"); console.log(greeting);A. Hello, Alice
B. undefined
C. Syntax error
D. Function declaration
Q. What is the output of this code?
var x = 10; var y = "10"; console.log(x === y);A. true
B. false
C. Syntax error
D. undefined
Q. What is the output of this code?
var myObj = { name: "John", age: 30, city: "New York" }; console.log(myObj.name);A. John
B. 30
C. New York
D. undefined
Q. What is the output of this code?
var num = 10; function changeNum() { num += 5; return num; } console.log(changeNum()); console.log(num);A. 15, 15
B. 15, 10
C. 10, 15
D. Syntax error
Q. What is the output of this code?
var myString = "Hello, world!"; console.log(myString.slice(2, 5));A. ll
B. lo
C. o, w
D. Error: Invalid arguments