Declaringoperators.md - brainchildservices/curriculum GitHub Wiki
Slide 1
Declaring and initializing Operators
Assignment
Assign values to variables
let x = 5; // assign the value 5 to x
let y = 2; // assign the value 2 to y
The assignment operator (=
) assigns a value to a variable.
let x = 10;
Slide 1
Adding
The addition operator (+
) adds numbers:
let x = 5;
let y = 2;
let z = x + y; //Output: 7
The addition assignment operator (+=
) adds a value to a variable.
let x = 10;
x += 5; //Output:- 15
Slide 1
Multiplying
let x = 5;
let y = 2;
let z = x * y; Output//10
The *=
assignment operator multiplies a variable.
let x = 10;
x *= 5; //Output:- 50
Slide 1
Subtracting
The subtraction operator (-
) subtracts numbers.
let x = 5;
let y = 2;
let z = x - y; //Output: 3
Slide 1
Decrementing
The decrement operator (--
) decrements numbers.
let x = 5;
x--;
let z = x; Output:- 4