Writeln in JavaScript: W3Schools Guide

Sarah Jul 13, 2026

The `writeln` statement in JavaScript, used in web development, is a print function that outputs the content in the console and also moves to the next line. It's particularly useful for debugging or displaying intermediate results during the development process. Let's dive into how to use `writeln` with examples, and also explore some related features provided by W3Schools for learning and practicing JavaScript.

Javascript Cheet cheet
Javascript Cheet cheet

JavaScript's `writeln` is similar to the `console.log()` method, but it automatically inserts a newline character at the end of the output, making it convenient for multi-line outputs and clear console reading.

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

Using `writeln` in JavaScript

To use `writeln`, simply include it in your JavaScript code. It outputs the given value to the console and then jumps to the next line, making the output more readable and well-organized.

JavaScript Full Notes Every Beginner Must Save ๐Ÿ’ก
JavaScript Full Notes Every Beginner Must Save ๐Ÿ’ก

Syntax: `writeln(value)`

Basic Usage

JavaScript | Chapter 2 ๐Ÿ“–| Part 1 โœจ
JavaScript | Chapter 2 ๐Ÿ“–| Part 1 โœจ

To output a simple string, use `writeln` with a string value.

```javascript writeln("Hello, W3Schools! How are you today?"); ```

Outputting Variables

You can also output the value of a variable using `writeln`.

JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming

```javascript let message = "Hello, World!"; writeln(message); ```

`writeln` vs `console.log()`

While both `writeln` and `console.log()` serve the same purpose of printing content to the console, they have some differences in how they handle newlines and formatting.

`writeln`: Automatically adds a newline character, keeps the output organized by default, but doesn't support style and color formatting as extensively as `console.log()`.

JavaScript Template Literals: Write Cleaner & Dynamic Strings ๐Ÿ“
JavaScript Template Literals: Write Cleaner & Dynamic Strings ๐Ÿ“

`console.log()`: Requires using `console.log("\n")` for line breaks, supports formatting with styles and colors, and is more versatile for complex outputs.

Using`writeln` with Variable Interpolation

Start Writing JavaScript with AI Assistance ๐Ÿš€
Start Writing JavaScript with AI Assistance ๐Ÿš€
an info sheet with different types of web pages
an info sheet with different types of web pages
๐Ÿ”ฅ JavaScript Chapter 1 Notes 2026 ๐Ÿ“’โœจ
๐Ÿ”ฅ JavaScript Chapter 1 Notes 2026 ๐Ÿ“’โœจ
Code Geek | Simple JavaScript tutorial notes for beginners ๐Ÿ‘‡ | Facebook
Code Geek | Simple JavaScript tutorial notes for beginners ๐Ÿ‘‡ | Facebook
JavaScript๏ฝœDOMๆ“ไฝœ(่ฆ็ด ใฎๅ–ๅพ—, ่ฟฝๅŠ , ๅ‰Š้™ค) - ใ‚ใใ‚ใBank
JavaScript๏ฝœDOMๆ“ไฝœ(่ฆ็ด ใฎๅ–ๅพ—, ่ฟฝๅŠ , ๅ‰Š้™ค) - ใ‚ใใ‚ใBank
Html notes
Html notes
Javascript Fundamental
Javascript Fundamental
JavaScript Basics | Chapter 1 ๐Ÿ“– | Part 1
JavaScript Basics | Chapter 1 ๐Ÿ“– | Part 1
๐Ÿ“˜ JavaScript Basics| Linking JS File to HTML | Chapter 2 ๐Ÿ“– Part 2
๐Ÿ“˜ JavaScript Basics| Linking JS File to HTML | Chapter 2 ๐Ÿ“– Part 2
the web programming poster is shown
the web programming poster is shown
Javascript Explained | Sketch-notes PART3
Javascript Explained | Sketch-notes PART3
JavaScript Basics You MUST Know
JavaScript Basics You MUST Know
CSS Notes for Beginners (Easy + Quick Guide) ๐ŸŽจ
CSS Notes for Beginners (Easy + Quick Guide) ๐ŸŽจ
the web programming poster is shown
the web programming poster is shown
JavaScript Basics | Chapter 1 ๐Ÿ“– | Part 2
JavaScript Basics | Chapter 1 ๐Ÿ“– | Part 2
JavaScript Works in the Browser
JavaScript Works in the Browser
Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)
Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)
JavaScript road map #JavaScript #js #learn #gk #JavaScript #AI #WebDevelopment
JavaScript road map #JavaScript #js #learn #gk #JavaScript #AI #WebDevelopment
The <script> Tag in HTML
The <script> Tag in HTML
Javascript window.confirm() method | Javascript tutorial
Javascript window.confirm() method | Javascript tutorial

With JavaScript ES6 template literals, you can use backticks (`) to create string expressions, allowing you to embed variables directly in the string without concatenation.

```javascript let name = "John Doe"; writeln(`Hello, ${name}!`); ```

Using `writeln` for Multi-line Outputs

Since `writeln` automatically inserts line breaks, it's ideal for multi-line messages where readability is crucial.

```javascript writeln("This is a\nmulti-line\ mรครคr Jagะณะต message!"); ```

W3Schools is an excellent resource for learning and practicing JavaScript, including the `writeln` statement and related console API methods. Their interactive tutorials and reference pages make it easy to understand and experiment with various JavaScript features.

Now that you're familiar with using `writeln` and its differences from `console.log()` in JavaScript, it's time to practice and explore more features at W3Schools. Happy coding, and keep refining your development skills!