JavaScript Syntax Rules
JavaScript Syntax Rules
JavaScript has a syntax that’s similar to many C-style programming languages, though with its unique aspects. Most JavaScript statements syntax has the same syntax as in C language.
Some of the basic JavaScript syntax rules are as follows:
Case Sensitivity
JavaScript is case-sensitive. myVar
and MyVar
are different identifiers.
JavaScript Statements
JavaScript statement is terminated with a semicolon(;)
Each instruction is a statement. Use semicolons (;
) to separate them.
let x = 5;
let y = 10;
console.log(x + y);
JavaScript Comments
// Single-line comment
/* Multi-line
comment */
JavaScript Variables
Declared using var
, let
, or const
.
let name = "Alice";
const pi = 3.14;
var age = 25;
JavaScript Identifiers
- Must start with a letter, underscore (
_
), or dollar sign ($
). - Cannot start with a number.
- Examples:
userName
,_count
,$price
JavaScript Data Types
- Number:
10
,3.14
- String:
"Hello"
,'World'
- Boolean:
true
,false
- Null:
null
- Undefined:
undefined
- Objects & Arrays:
{}
,[]
Operators
- Arithmetic:
+
,-
,*
,/
,%
- Assignment:
=
,+=
,-=
- Comparison:
==
,===
,!=
,<
,>
- Logical:
&&
,||
,!
JavaScript Functions
function greet(name) {
return "Hello " + name;
}
const add = (a, b) => a + b;
JavaScript Blocks
Use { }
to define block scope.
if (true) {
let x = 5;
console.log(x);
}
Whitespace
JavaScript ignores extra spaces, tabs, and line breaks. Use them only for readability.
—
JavaScript Tutorials
JavaScript tutorials on this website can be found at:
To learn more about JavaScript, visit
- https://www.javascript.com/