CodeBlanks Logo Icon CodeBlanks

Console

Learn console.log and console.warn.

What is console?

console is JavaScript's built-in debugging tool. console.log prints a value, console.warn issues a warning, console.error reports an error. All output appears in Flipper's Logs tab and the Metro terminal.

Console is the fastest debugging method. To see a variable's value you just write console.log('count:', count). warn and error are highlighted in yellow/red; this separates them from ordinary log calls. Leaving log calls in production can affect performance; cleaning them before release is a good habit.

Log levels

Console has three main levels. console.log is for info; it appears white in Flipper. console.warn reports a possible issue; it is highlighted yellow. console.error reports a serious error; it is highlighted red.

The level choice shows the output's severity. Use log for info, warn for situations that need attention but are not critical, and error for real errors. This distinction makes quick scanning in the Logs tab easier. Using error for a non-error case can panic your team. The right level should match the message's severity.

Practice Write a console.warn

Write a warning message. Use console.warn; the message is 'Low battery'. Make sure the message is in quotes.

Starter code

App.js
// Write a warning message; use console.warn
// Put the message in quotes

Sample solution

App.js
console.warn("Low battery");

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Match each method to its role

Term Meaning
console.log Prints info
console.warn Issues warning
console.error Reports error
console.table Draws a table

2 The console.error call

Question
console.____('Hata oluştu');
Answer
console.error('Hata oluştu');

Explanation: console.error reports an error message.

3 What does console.warn do?

App.js
console.warn('düşük pil');
  • Prints info
  • Shows a warning Correct answer
  • Stops the program
  • Throws an error

Explanation: console.warn shows a warning.

All lessons in Intermediate