Bird
Raised Fist0
Javascriptprogramming~20 mins

Output using console.log in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Console Log Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of console.log with template literals
What is the output of this code?
const name = "Alice";
const age = 30;
console.log(`Name: ${name}, Age: ${age}`);
Javascript
const name = "Alice";
const age = 30;
console.log(`Name: ${name}, Age: ${age}`);
AName: Alice Age: 30
BName: name, Age: age
CName: ${name}, Age: ${age}
DName: Alice, Age: 30
Attempts:
2 left
💡 Hint
Look how template literals use ${} to insert variables inside backticks.
❓ Predict Output
intermediate
2:00remaining
Output of console.log with multiple arguments
What will this code print?
console.log("Hello", "World", 2024);
Javascript
console.log("Hello", "World", 2024);
AHello World 2024
BHello, World, 2024
CHelloWorld2024
D"Hello World 2024"
Attempts:
2 left
💡 Hint
console.log prints each argument separated by spaces.
❓ Predict Output
advanced
2:00remaining
Output of console.log with undefined variable
What happens when you run this code?
let x;
console.log(x);
Javascript
let x;
console.log(x);
A0
Bnull
Cundefined
DReferenceError
Attempts:
2 left
💡 Hint
Variables declared but not assigned have a special value.
❓ Predict Output
advanced
2:00remaining
Output of console.log with object and array
What will this code print?
const obj = {a: 1, b: 2};
const arr = [3, 4];
console.log(obj, arr);
Javascript
const obj = {a: 1, b: 2};
const arr = [3, 4];
console.log(obj, arr);
A{ a: 1, b: 2 } [ 3, 4 ]
B[object Object] [3,4]
C{a:1,b:2},[3,4]
Da:1,b:2 3,4
Attempts:
2 left
💡 Hint
console.log prints objects and arrays in readable form separated by spaces.
🧠 Conceptual
expert
3:00remaining
Behavior of console.log with asynchronous code
What is the output order of this code?
console.log('Start');
setTimeout(() => console.log('Timeout'), 0);
console.log('End');
Javascript
console.log('Start');
setTimeout(() => console.log('Timeout'), 0);
console.log('End');
AEnd\nStart\nTimeout
BStart\nEnd\nTimeout
CTimeout\nStart\nEnd
DStart\nTimeout\nEnd
Attempts:
2 left
💡 Hint
setTimeout with 0 delay runs after current code finishes.

Practice

(1/5)
1. What does console.log do in JavaScript?
easy
A. It creates a new variable.
B. It stops the program from running.
C. It prints messages or values to the console.
D. It reads input from the user.

Solution

  1. Step 1: Understand the purpose of console.log

    console.log is used to show messages or values in the console, helping to see what the program does.
  2. Step 2: Compare options with the purpose

    Only It prints messages or values to the console. matches this purpose. Other options describe different actions.
  3. Final Answer:

    It prints messages or values to the console. -> Option C
  4. Quick Check:

    console.log prints output [OK]
Hint: Remember: console.log shows info in the console [OK]
Common Mistakes:
  • Thinking console.log stops the program
  • Confusing console.log with input functions
  • Assuming console.log creates variables
2. Which of the following is the correct syntax to print "Hello World" using console.log?
easy
A. console.log: 'Hello World'
B. console.print('Hello World')
C. print.console('Hello World')
D. console.log('Hello World')

Solution

  1. Step 1: Identify correct console.log syntax

    The correct way to print is console.log('text') with parentheses and quotes around the text.
  2. Step 2: Check each option

    console.log('Hello World') uses correct syntax. Options A, B, and C use wrong method names or punctuation.
  3. Final Answer:

    console.log('Hello World') -> Option D
  4. Quick Check:

    console.log('text') is correct syntax [OK]
Hint: Use console.log() with parentheses and quotes [OK]
Common Mistakes:
  • Using console.print instead of console.log
  • Missing parentheses
  • Using colon instead of parentheses
3. What will be the output of the following code?
let x = 5;
let y = 10;
console.log(x + y);
medium
A. 15
B. 510
C. x + y
D. undefined

Solution

  1. Step 1: Understand the variables and operation

    Variables x and y hold numbers 5 and 10. The expression x + y adds these numbers.
  2. Step 2: Calculate the sum

    5 + 10 equals 15, so console.log(x + y) prints 15.
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    5 + 10 = 15 [OK]
Hint: Add numbers inside console.log to get sum [OK]
Common Mistakes:
  • Thinking + concatenates as strings here
  • Printing variable names instead of values
  • Expecting undefined output
4. Find the error in this code:
console.log('Hello World'
medium
A. Missing closing parenthesis
B. Missing semicolon
C. Wrong quotes used
D. console.log is not a function

Solution

  1. Step 1: Check the syntax of console.log

    The function call must have matching opening and closing parentheses.
  2. Step 2: Identify the missing part

    The code misses the closing parenthesis after the string, causing a syntax error.
  3. Final Answer:

    Missing closing parenthesis -> Option A
  4. Quick Check:

    Parentheses must match in function calls [OK]
Hint: Count opening and closing parentheses carefully [OK]
Common Mistakes:
  • Ignoring missing parenthesis
  • Thinking semicolon is mandatory error
  • Confusing quotes with parentheses
5. What will this code print?
let a = 3;
let b = '4';
console.log(a + b);
hard
A. 7
B. 34
C. undefined
D. TypeError

Solution

  1. Step 1: Understand the types of variables

    Variable a is a number 3, b is a string '4'.
  2. Step 2: Apply + operator with mixed types

    When adding number + string, JavaScript converts number to string and concatenates, so 3 + '4' becomes '34'.
  3. Final Answer:

    34 -> Option B
  4. Quick Check:

    Number + string concatenates as string [OK]
Hint: Number + string joins as text, not sums [OK]
Common Mistakes:
  • Expecting numeric sum
  • Thinking it causes error
  • Ignoring type conversion rules
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard