What Are Whitespace and Line Breaks in JavaScript?


JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. You can use spaces, tabs, and newlines freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.

JavaScript ignores whitespaces. For example, the following are same:

var employee = "Amit";
var employee="Amit";

Line breaks in JavaScript:

<!DOCTYPE html>
<html>
   <body>
      <p>Line-break in an alert box. Click below button.</p>
      <button onclick="alert('Hi
Welcome to Tutorialspoint')">Click</button>    </body> </html>

Updated on: 12-Sep-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements