JavaScript Console API (log, error, table) Quiz

JavaScript
0 Passed
0% acceptance

Explore 40 questions that cover console.log, console.error, console.table, message formatting, styling, grouping, timing, assertions, debugging workflows, clearing output, and practical logging best practices in JavaScript.

40 Questions
~80 minutes
1

Question 1

What is the console API primarily used for?

A
Inspecting and logging information during development
B
Styling HTML elements directly
C
Serving static assets
D
Declaring CSS variables
2

Question 2

Which statement describes console.log?

A
It prints informational messages to the console
B
It throws errors to halt execution
C
It formats HTML elements
D
It clears localStorage
3

Question 3

Which placeholder inserts a string when using console.log formatting?

A
%s
B
%d
C
%f
D
%o
4

Question 4

Which console method reports error-level logs with stack traces in most browsers?

A
console.error
B
console.info
C
console.count
D
console.clear
5

Question 5

What does this snippet produce?

javascript
const users = [
  { id: 1, name: 'Ana' },
  { id: 2, name: 'Raj' }
]
console.table(users)
A
A table with id and name columns for each user
B
A JSON string
C
An error about console.table
D
Only the first user printed
6

Question 6

Which placeholder highlights numbers in console.log?

A
%d or %i
B
%c
C
%s
D
%O
7

Question 7

How can you style console output with CSS?

A
Use console.log("%cStyled", "color: red")
B
Attach a stylesheet to console
C
Call console.style
D
Use HTML tags directly
8

Question 8

Which technique helps highlight variable names next to their values?

javascript
const total = 42
console.log({ total })
A
It prints { total: 42 } making the label obvious
B
It prints 42 without context
C
It clears the console
D
It throws because objects cannot be logged
9

Question 9

What is a benefit of logging template literals?

A
They make multi-line logs and embed expressions cleanly
B
They persist logs to disk
C
They auto-hide secrets
D
They disable console.error
10

Question 10

Which practice keeps console output organized?

A
Prefix messages with contextual tags like [Auth] or [Cart]
B
Disable logging entirely
C
Console log every variable change
D
Throw errors instead of logging
11

Question 11

Which method prints an object with its properties expanded immediately?

javascript
const user = { id: 7, name: 'Mina', meta: { active: true } }
console.dir(user)
A
console.dir shows the full object tree for inspection
B
console.dir throws because objects must be stringified
C
console.dir clears the console
D
console.dir minifies the object
12

Question 12

What is the advantage of logging a Map with console.table?

A
It displays key/value pairs in rows for quick inspection
B
It sorts keys alphabetically by default
C
It serializes the Map to JSON automatically
D
It hides duplicate entries
13

Question 13

Which method counts how many times a label has been logged?

A
console.count
B
console.time
C
console.assert
D
console.group
14

Question 14

What output results from this code?

javascript
const foo = 'A'
const bar = 3
console.log({ foo, bar })
A
{ foo: "A", bar: 3 }
B
"A3"
C
["A", 3]
D
undefined
15

Question 15

Why should sensitive data be filtered before logging objects?

A
Console histories can persist and expose secrets to others
B
Logging automatically encrypts secrets
C
console.log uploads data to the server
D
Objects cannot be logged otherwise
16

Question 16

What does the following produce?

javascript
console.log('%cWarning', 'color: orange; font-weight: bold')
A
The word Warning styled in orange bold text
B
Plain text "Warning"
C
An error message
D
CSS injected into the page
17

Question 17

What is printed here?

javascript
console.group('Auth')
console.log('Login start')
console.groupEnd()
A
Login start indented under an "Auth" label
B
Only Login start
C
An error about group usage
D
Nothing
18

Question 18

Given the code, what is displayed?

javascript
console.groupCollapsed('Data')
console.log('Fetch users')
console.log('Fetch posts')
console.groupEnd()
A
A collapsed "Data" group containing two logs
B
All logs expanded by default
C
Only the first log
D
SyntaxError
19

Question 19

What happens if console.groupEnd is called without a matching console.group?

A
Most consoles ignore the call and continue logging
B
A SyntaxError is thrown
C
The console clears automatically
D
The browser crashes
20

Question 20

Which scenario benefits from console.group?

A
Logging related steps (start, success, failure) under one collapsible label
B
Clearing all logs
C
Measuring code execution time
D
Counting function calls
21

Question 21

What is output here?

javascript
console.time('fetch')
// ... async work
console.timeEnd('fetch')
A
fetch: <duration> ms
B
The async result value
C
Nothing
D
An error
22

Question 22

What happens if console.timeEnd is called with a label that was never started?

A
Most browsers warn that the label does not exist
B
It throws a SyntaxError
C
It clears the console
D
It silently starts a timer
23

Question 23

What does the following assert do?

javascript
console.assert(Array.isArray(users), 'Users must be an array')
A
Logs the message only if the condition is false
B
Throws an exception
C
Always logs the message
D
Clears the console
24

Question 24

Why use console.time when profiling specific blocks?

javascript
console.time('task')
expensiveWork()
console.timeEnd('task')
A
It prints how long expensiveWork took without setting breakpoints
B
It throws if the function is slow
C
It replaces the Performance API entirely
D
It cancels expensiveWork
25

Question 25

What is a drawback of leaving console.time in production code?

A
Excessive timers create noise and can reveal implementation details
B
Browsers crash immediately
C
Promises stop working
D
CSS breaks
26

Question 26

What does this snippet produce?

javascript
try {
  throw new Error('Failed to save')
} catch (err) {
  console.error('Save error:', err)
}
A
A red error log with the message and stack trace
B
A browser alert
C
An automatic retry
D
No output
27

Question 27

When should console.error be preferred over console.log?

A
When the message indicates a failure that needs attention
B
When logging feature flags
C
When measuring timing
D
When clearing the console
28

Question 28

How can console.table support debugging API responses?

A
By revealing nested arrays or objects per row, making anomalies obvious
B
By hiding all null values
C
By caching the response
D
By retrying the request
29

Question 29

Why is console.log often replaced with debugger statements during deep investigation?

A
Debugger pauses execution so you can inspect state interactively
B
Debugger speeds up code
C
Debugger writes to disk
D
Debugger blocks console usage
30

Question 30

What is a common best practice after finishing debugging?

A
Remove or guard console statements to avoid cluttering production logs
B
Leave all console logs to help users
C
Convert logs to alerts
D
Wrap logs in eval
31

Question 31

What happens when running this snippet?

javascript
console.log('A')
console.clear()
console.log('B')
A
Only "B" remains visible in most devtools
B
Both logs remain
C
An error occurs
D
The browser reloads
32

Question 32

What is the result of console.count("api") repeated three times?

A
api: 1, api: 2, api: 3
B
1, 2, 3 without labels
C
A table of counts
D
No output
33

Question 33

What does console.countReset("api") do?

A
Resets the counter for label "api" to zero
B
Clears the console
C
Starts a timer
D
Throws an error
34

Question 34

Which method outputs a warning with stack trace but lower severity than console.error?

A
console.warn
B
console.assert
C
console.table
D
console.trace
35

Question 35

What does console.trace do?

A
Prints the current call stack without throwing
B
Clears the console
C
Starts a CPU profile
D
Measures time
36

Question 36

Why avoid leaving verbose console.log statements in production?

A
They can expose sensitive data and hurt performance
B
Browsers ban console.log in production
C
They disable CSS
D
They reduce screen resolution
37

Question 37

Which approach makes console logging configurable?

A
Wrap console methods in a logger that checks environment flags
B
Use eval to toggle logs
C
Replace console with alert
D
Disable devtools
38

Question 38

How can console.assert improve defensive programming?

A
It calls out unexpected states without stopping execution
B
It retries failed requests
C
It encrypts logs
D
It automatically fixes bugs
39

Question 39

What is a best practice when combining console.log with objects?

A
Use shallow clones or structured logging to avoid mutating the logged object later
B
Log the same object repeatedly to ensure accuracy
C
Convert objects to strings manually
D
Use console.clear before each log
40

Question 40

Which guideline keeps console usage sustainable?

A
Define logging levels and remove noisy logs before shipping
B
Never log errors
C
Log every function entry and exit in production
D
Rely solely on console.error

QUIZZES IN JavaScript