JavaScript Statements
JavaScript Statements
1 JavaScript Statements
2 JavaScript Statements
A computer program is a list of “instructions” to be “executed” by a computer.
Values,
Operators,
Expressions,
Keywords, and
Comments.
3 JavaScript Values
The JavaScript syntax defines two types of values: Fixed values and Variable values
JavaScript Literals
Numbers are written with or without decimals
Automatically
Using var
Using let
Using const
5 JavaScript Identifiers
All JavaScript variables must be identified with unique names called identifiers.
String An Object
Number An array
Bigint A date
Boolean
Undefined
Null
Symbol
Object
7 JavaScript Data Type Examples
8 JavaScript Operators
There are different types of JavaScript operators:
Arithmetic operators
Assignment operators
Comparison operators
String operators
Logical operators
Bitwise operators
Ternary operators
Type operators
9 JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers.
10 JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables.
11 JavaScript Comparison Operators
12 JavaScript Logical Operators
If a JavaScript statement does not fit on one line, the best practice to break it is after an operator.
JavaScript statements can be grouped together in code block, inside curly bracket { … }.
Comments can also be used to prevent execution, when testing alternative codes.
Create the text “My name” and another text “Simon”. Using concatenation, add these two strings together to
create the text: ‘My name is Simon’.
You order a T-shirt for $10, socks for $8, and dinner plates for $20. Use JavaScript to calculate the total cost of
your order.
At a restaurant, you order 1 coffee ($5) and 1 bagel ($3). Using Math, calculate the total cost, and using
concatenation, create the text: ‘Total cost: $ ___’ (replace ___ with the total you calculated).
18