JavaScript Syntax
Syntax Rules
Syntax are the rules how programs must be constructed:
let x = 5;
let y = 6;
// How to Compute values:
let z = x + y;
// I am a Comment. I do Nothing
JavaScript Values
The JavaScript syntax defines two types of values:
- Literals (Fixed values)
- Variables (Variable values)
JavaScript Literals
The most important syntax rules forliterals (fixed values) are:
Numbers are written with or without decimals:
Strings are text, written within double or single quotes:
JavaScript Keywords
JavaScriptkeywords are used to definesactions to be performed.
Thelet andconst keywords create variables:
Note
JavaScript keywords arecase-sensitive.
JavaScript does not interpretLET orLet as the keywordlet.
JavaScript Variables
Variables are containers forstoring data values.
Variables must beidentified withunique names.
JavaScript Identifiers
Anidentifier is thename you give to a variable.
Rules for identifiers:
- Must start with a letter, _, or $
- Can contain digits after the first character
- Cannot be a reserved keyword (let, const, if, etc.)
- Are case-sensitive
JavaScript Operators
JavaScriptassignment operators (=) assign values to variables:
JavaScript usesarithmetic operators (+-*/ ) tocompute values:
JavaScript Expressions
An expression is a combination of values, variables, and operators, which computes to a value.
Examples
(5 + 6) * 10 evaluates to 110:
Expressions can also contain variable:
"John" + " " + "Doe", evaluates to "John Doe":
JavaScript is Case Sensitive
JavaScript identifiers arecase sensitive.
The variableslastName andlastname, are different variables:
JavaScript and Camel Case
Historically, programmers have used different ways of joining multiple words into one variable name:
Hyphens:
first-name, last-name, master-card, inter-city.
Hyphens are not allowed in JavaScript. They are reserved for subtractions.
Underscore:
first_name, last_name, master_card, inter_city.
Upper Camel Case (Pascal Case):
FirstName, LastName, MasterCard, InterCity.
Lower Camel Case:
firstName, lastName, masterCard, interCity.
JavaScript programmers tend to use lower camel case.
Video: JavaScript Syntax



