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

JavascriptWeb DevelopmentObject Oriented Programming

Yes, we can use a new line using “\n” 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", "\n", 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]
}
raja
Published on 12-Sep-2020 08:26:42
Advertisements