Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS White Space

JavaScript disregards multiple spaces. You can incorporate whitespace into your script to enhance readability.

The subsequent lines hold the same meaning:

let person = “Hege”;
let person=“Hege”;

It’s considered good practice to include spaces around operators ( = + – * / ).

let x = y + z;

JavaScript Line Length and Line Breaks

To improve readability, programmers often limit code lines to 80 characters. If a JavaScript statement exceeds this length, it’s best to break it after an operator.

Example

document.getElementById(“demo”).innerHTML =
“Hello Dolly!”;

JavaScript Code Blocks

JavaScript statements can be grouped within code blocks, which are delimited by curly brackets {...}. This organization allows for collective execution, often seen in JavaScript functions.

Example

function myFunction() {
  document.getElementById(“demo1”).innerHTML = “Hello Dolly!”;
  document.getElementById(“demo2”).innerHTML = “How are you?”;
}