Page 128 - CITS - Computer Software Application -TT
P. 128
COMPUTER SOFTWARE APPLICATION - CITS
Value = undefined
In computer programs, variables are often declared without a value. The value can be something that has to be
calculated, or something that will be provided later, like user input.
A variable declared without a value will have the value undefined.
The variable carName will have the value undefined after the execution of this statement:
Example
let carName;
Re-Declaring JavaScript Variables
If you re-declare a JavaScript variable declared with var, it will not lose its value.
The variable carName will still have the value “Volvo” after the execution of these statements:
Example
var carName = “Volvo”;
var carName;
Note
You cannot re-declare a variable declared with let or const.
This will not work:
let carName = “Volvo”;
let carName;
JavaScript Operators
Operators are the symbols between values that allow different operations like addition, substraction, multiplication,
and more. JavaScript has dozens operators, so let’s focus on the ones you’re likely to see most often.
Operators is used to perform some operation on data.
There are many type of Operators:
Arithmetic Operator (+): JavaScript uses arithmetic operators ( + - * / ) to compute values:
(5 + 6) * 10
Assignment Operator (%): JavaScript uses an assignment operator ( = ) to assign values to variables:
let x, y;
x = 5;
y = 6;
Exponentiation Operator (**): JavaScript uses an exponentiation operator ( ** ) to compute the power values to
variables:
let x, y;
x = 5;
y = 2;
d = x ** y
Modulus Operator (**): JavaScript uses an modulus operator ( % ) to check the remainder values to variables:
let x, y;
x = 8;
y = 2;
d = x % y
115
CITS : IT&ITES - Computer Software Application - Lesson 37 - 46