Console log new line js
In JavaScript, you can use the following methods to log a new line to the console:
console.log()
with a newline character:console.log("Hello"); console.log("\n"); console.log("World!");
This will output:
Hello World!
console.log()
with a newline string:console.log("Hello"); console.log("World!"); console.log("\n\n");
This will output:
Hello World!
console.log()
with a newline string and a space:console.log("Hello"); console.log("World!"); console.log("\n ");
This will output:
Hello World!
console.log()
with a newline string and a tab:console.log("Hello"); console.log("World!"); console.log("\n\t");
This will output:
Hello World!
- Using
console.log()
with an array of strings:console.log(["Hello", "World!", "\n"]);
This will output:
Hello World!
Note that the
\n
character is a newline character, which is a special character that tells the console to move to the next line.