LearnFrenzy
Sign in Take a free test

JavaScript Basics · Exercise 2 of 4

JavaScript Basics Predict the Output

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each JavaScript program and choose what it prints. Every program was run on Node.js as a normal (non-strict) script unless it says "use strict", so the answers are the real output.

Question 11 Easy

What does the following JavaScript code print (console output, as in Node.js)?

main.js
let total = 10;
let Total = 20;
let TOTAL = total + Total;
console.log(total, Total, TOTAL);
A 10 20 30
B 20 20 40
C SyntaxError: total has already been declared
D 30 30 30
Question page & discussion
Question 12 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
"use strict";
function show() {
  return this;
}
console.log(show());
A The global object
B {}
C undefined
D null
Question page & discussion
Question 13 Hard

What does the following JavaScript code print (console output, as in Node.js)?

main.js
function kind() {
  return typeof this;
}
console.log(kind(), this === undefined);
A undefined true
B object true
C object false
D function false
Question page & discussion
Question 14 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
function setScore() {
  score = 90;        // no let, const or var
}
setScore();
console.log(score);
A ReferenceError: score is not defined
B undefined
C 90
D SyntaxError
Question page & discussion
Question 15 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log([1, "two", true]);
console.log({ name: "Asha", age: 21 });
A [ 1, 'two', true ] { name: 'Asha', age: 21 }
B 1,two,true [object Object]
C [1,"two",true] {"name":"Asha","age":21}
D [ 1, two, true ] { name: Asha, age: 21 }
Question page & discussion
Question 16 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log(10 / 4);
console.log(10 / 0);
console.log(-10 / 0);
A 2.5 Infinity -Infinity
B 2 Error Error
C 2.5 NaN NaN
D 2 Infinity -Infinity
Question page & discussion
Question 17 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
{
  let inner = 1;
}
console.log(typeof inner);
A undefined
B number
C ReferenceError: inner is not defined
D object
Question page & discussion
Question 18 Medium

What does the following JavaScript code print (console output, as in Node.js)?

main.js
greet("Asha");

function greet(name) {
  console.log(`Hello, ${name}`);
}
A ReferenceError: greet is not defined
B TypeError: greet is not a function
C undefined
D Hello, Asha
Question page & discussion
Question 19 Hard

What does the following JavaScript code print (console output, as in Node.js)?

main.js
let x = (1, 2, 3);
let y = (x++, x * 10);
console.log(x, y);
A 4 40
B 3 30
C 1 10
D 4 30
Question page & discussion
Question 20 Hard

What does the following JavaScript code print (console output, as in Node.js)?

main.js
const first = "Learn"
const word = first
+ "Frenzy"
console.log(word)
A Learn
B SyntaxError
C LearnFrenzy
D Learn Frenzy
Question page & discussion
Up next · Exercise 3Find the Error15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links