Coding/Learn/javascript/first program
JavaScript Foundational Course
01.Introduction to JavaScript & V8 Engine
02.Console Output & Program Flow
03.Variables & Data Types (let, const, typeof)
04.Template Literals & String Interpolation
05.Type Coercion & Strict Equality (=== vs ==)
06.Arithmetic, Math Object & Modulo
07.Conditionals & If / Else Branching
08.Logical Operators & Nullish Coalescing (??)
09.Ternary Operator & Switch Statements
10.While & Do-While Loops
11.Standard For Loops & Iteration
12.Loop Control (Break & Continue)
13.Functions, Arrow Syntax & Return Values
14.Default Parameters, Rest & Spread Syntax
15.Arrays, Indexing & Mutating Methods
16.Array Iterators (map, filter, reduce)
17.Objects, Key-Value Pairs & Destructuring
18.Scope, Lexical Environment & Closures
19.Asynchronous JavaScript (Promises & Async/Await)
20.Capstone: Interactive E-Commerce Cart & Ledger Engine
Course Certificate0%

Complete all lessons to earn

LearnConsole Output & Program Flow
2 / 20 0%
Lesson 02 of 20
5 mins read

Console Output & Program Flow

PreviousNext Lesson
In Plain English

JavaScript programs execute sequentially from top to bottom. The global console object provides rich methods like log(), info(), warn(), and error() to inspect state during execution.

The Mental Model

"The console is the developer’s cockpit telemetry feed—it gives you instant visibility into every variable and checkpoint as your program runs."

Deep Dive: How It Works

Sequential Execution: Each statement is processed in order before moving to the next line.

Semicolons: Semicolons separate statements. While Automatic Semicolon Insertion (ASI) exists, explicit semicolons prevent edge-case parsing ambiguities.

Comments: Use // for single-line comments and /* ... */ for multi-line annotations.

Syntax Blueprint

console.log(val1, val2, ...) ──▶ Formatted output separated by spaces

console.log accepts multiple comma-separated arguments and prints them sequentially.

PointCore Rules to Remember

Point star
console.log(): Standard output method for strings, numbers, objects, and arrays.
Point star
Multi-argument Logging: console.log("Status:", "OK", 200) prints "Status: OK 200".
Point star
Code Structure: Clean indentation and comments make code maintainable and easy to follow.

Common Beginner Traps & How to Fix Them

Mistake:Logging an undefined variable before initialization.

Why it happens: Referencing variables before declaration throws a ReferenceError.

How to fix: Always declare variables before using them in console statements.

Pro Tip: You can pass objects to console.log({ user, status }) to quickly print labeled variable values.

Live Interactive Example

Hit Run Code to see it live
Console Logging Patterns
JavaScript ES2024
1
2
3
4
5
6
7
8
Output Console
Click "Run Code" to view the rendered output.
How it works: Each console.log call outputs a distinct line with formatted values.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Log multi-variable system status

  • PointDeclare a const app = "ZenEngine";
  • PointDeclare a const version = "3.4";
  • PointPrint "App: ZenEngine | Version: 3.4" using console.log().
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates