In JavaScript, can be use a new line in console.log?


Yes, we can use a new line using “
” in console.log(). Following is the code −

Example

const studentDetailsObject = new Object()
studentDetailsObject.name = 'David'
studentDetailsObject.subjectName = 'JavaScript'
studentDetailsObject.countryName = 'US'
studentDetailsObject.print = function(){
   console.log('hello David');
}
console.log("studentObject", "
", studentDetailsObject);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo170.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo170.js
studentObject
{
   name: 'David',
   subjectName: 'JavaScript',
   countryName: 'US',
   print: [Function]
}

Updated on: 12-Sep-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements