JavaScript Statements
JavaScript Line Length and Line Breaks
For best readability, programmers often like to avoid code lines longer than 80 characters. If a JavaScript statement does not fit on one line, the best place to break it, is after an operator: document.getElementById("demo").innerHTML = "Hello Dolly!";
Statements
In HTML, JavaScript statements are "instructions" to be "executed" by the web browser.
JavaScript White Space
JavaScript ignores multiple spaces. You can add white space to your script to make it more readable. The following lines are equivalent: var person = "Hege"; var person="Hege"; A good practice is to put spaces around operators ( = + - * / ): var x = y + z;
JavaScript Code Blocks
JavaScript statements can be grouped together in code blocks, inside curly brackets {...}. The purpose of code blocks is to define statements to be executed together. One place you will find statements grouped together in blocks, is in JavaScript functions: function myFunction() { document.getElementById("demo1").innerHTML = "Hello Dolly!"; document.getElementById("demo2").innerHTML = "How are you?"; }
JavaScript Programs
Most JavaScript programs contain many JavaScript statements. The statements are executed, one by one, in the same order as they are written. JavaScript programs (and JavaScript statements) are often called JavaScript code.
What is the semicolon used for?
Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement. When separated by semicolons, multiple statements on one line are allowed.