➥ JS Tutorial
- JS HOME
- JS introduction
- JS Where to
- JS Output
- JS Statements
- JS Syntax
- JS Variables
- JS Operators
- JS Assignment
- JS Data Types
- JS Functions
- JS Objects
- JS Events
- JS Sting methods
- JS String Search
- JS Arrays Methods
- JS Arrays
- JS Sorting Arrays
- JS Array Iteration
- JS Math Object
- JS Comparison & Logical Operators
- JS if else and else if
- JS Switch Statement
- JS For Loop
- JS For In
- JS For Of
- JS While Loop
- JavaScript Break
- JS Sets
- JavaScript typeof
- JS Type Conversion
- JS Bitwise Operations
- JS JSON
- JS Best Practices
- JS Reserved Words
- JS Number Methods
➥ JS Objects
➥ JS Functions
➥ JS Classes
➥ JS HTML DOM
- JavaScript HTML DOM
- JS HTML DOM Document
- JS HTML DOM Elements
- Changing HTML
- JS Forms
- JS HTML DOM - CSS
- DOM Events
- HTML DOM Event Listener
➥ JS Browser BOM
➥ JS Web APIs
➥ JS AJAX
➥ JS JSON
Tutorial
JavaScript Statements
In HTML, JavaScript statements are "instructions" to be "executed" by the web browser.
Semicolons separate JavaScript statements.
Add a semicolon at the end of each executable statement:
Example:
let a, b, c;
EXAMPLE ❯
JavaScript Statements
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
Most JavaScript programs contain many JavaScript statements.
The statements are executed, one by one, in the same order as they are written.
EXAMPLE ❯
Semicolons ;
Semicolons separate JavaScript statements.
Add a semicolon at the end of each executable statement:
EXAMPLE ❯
When separated by semicolons, multiple statements on one line are allowed:
EXAMPLE ❯
JavaScript White Space
JavaScript ignores multiple spaces. You can add white space to your script to make it more readable.
Whitespace refers to characters which are used to provide horizontal or vertical space between other characters.
Whitespace is often used to separate tokens in HTML, CSS, JavaScript, and other computer languages.
The following lines are equivalent:
Example:
let person = "Hege";
let person="Hege";
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:
EXAMPLE ❯
JavaScript Keywords
JavaScript statements often start with a keyword to identify the JavaScript action to be performed.
Here is a list of some of the keywords you will learn about in this tutorial:
Keyword | Description |
---|---|
var | Declares a variable |
let | Declares a block variable |
const | Declares a block constant |
if | Marks a block of statements to be executed on a condition |
switch | Marks a block of statements to be executed in different cases |
for | Marks a block of statements to be executed in a loop |
function | Declares a function |
return | Exits a function |
try | Implements error handling to a block of statements |