The programming instructions written in a program in a programming language are known as statements. The order of execution of Statements is the same as they are written.
1. Semicolons:
- Semicolons separate JavaScript statements.
- A semicolon marks the end of a statement in javascript.
Example:
let a, b, c; a = 2; b = 3; c = a + b; console.log("The value of c is " + c + ".");
Output:
The value of c is 5.
Multiple statements on one line are allowed if they are separated with a semicolon.
a=2;b=3;z=a+b;
2. Code Blocks:
JavaScript statements can be grouped together inside curly brackets. Such groups are known as code blocks. The purpose of grouping is to define statements to be executed together.
Example: JavaScript function
function myFunction() { console.log("Hello"); console.log("How are you?"); } myFunction()
Output:
Hello How are you?
3. White Space:
Javascript ignores multiple white spaces.
Example:
console.log(10 * 2); console.log(10 * 2);
Output:
20 20
Both the result will be the same
4. Line Length and Line Breaks:
Javascript code’s preferred line length by most programmers is up to 80 characters. The best place to break a code line in Javascript, if it doesn’t fit, is after an operator.
Example:
document.getElementById("tech1").innerHTML = "Hello Tech!";
5. Keywords:
Keywords are reserved words and cannot be used as a variable name. A Javascript keyword tells about what kind of operation it will perform.
Recent Comments