How to use console.log() Method In Javascript

The console.log() method is a part of the JavaScript Console API, which provides methods for interacting with the browser’s console. It also returns a new line when the method is called and utilized so this approach can be used in place of an escape character.

Example: The below code uses the console.log() method to add a new line in JavaScript.

Javascript




console.log('GFG');
console.log();
console.log('w3wiki');


Output

GFG

w3wiki

How to Create a New Line in JavaScript ?

In JavaScript, a new line is typically represented by a specific escape sequence or character within a string. This is commonly used in various programming languages to control the formatting of text and create multiline strings. A new line can be made in JavaScript using the below-discussed methods.

Table of Content

  • Using Escape Sequence `\n`
  • Using ECMAScript6 (ES6) template literals
  • Using JavaScript console.log() Method
  • Using JavaScript document.write() Method
  • Using JavaScript document.writeln() Method

Similar Reads

Using Escape Sequence `\n`

The \n escape sequence represents a newline character in JavaScript strings and it can used to render a new line in JavaScript....

Using ECMAScript6 (ES6) template literals

...

Using JavaScript console.log() Method

In ECMAScript6, the backticks (“) are used to create a template literal. Template literals can span multiple lines without the need for escape characters, making it easier to write and read multiline strings in JavaScript....

Using JavaScript document.write() Method

...

Using JavaScript document.writeln() Method

The console.log() method is a part of the JavaScript Console API, which provides methods for interacting with the browser’s console. It also returns a new line when the method is called and utilized so this approach can be used in place of an escape character....

Contact Us