The rules of combinations of instructions is called a computer language, sometimes referred to as its syntax.
x = y + 5
Number 5 is called a literal value because it stands alone without being stored in a variable.
The = and + characters are operators, they perform actions with the values and variables such as assignment and mathematic operation.
The statement x = y + 5; tells the computer, to get the current value stored in the variable y, add that value with 5, then store the result back into another variable x.
Programs are just collections of many such statements, which together describe all the steps that it takes to perform your program.
Statements are made up of one or more expressions. An expression is any reference to a variable or value, or a set of variables and values combined with operators.
Here is an example:
x = y + 5
This statement has four expressions in it:
5is a literal value expression
yis a variable expression
y + 5is an arithmetic expression
x = y + 5is an assignment expression
Executing a Program
The program needs to be executed, also referred to as running the program.
For some computer languages, this translation of commands is typically done from top to bottom, line by line, every time the program is run, which is usually called interpreting the code.
For other languages, the translation is done ahead of time, called compiling the code, so when the program runs later, what's running is the already compiled computer instructions ready to go.
console.log(..) you can create output by printing the value to the console.
Another way of creating output that you can see is to run an
Operators are how we perform actions on variables and values.
There are two types of operators:
- Arithmetic Operators
- Logical Operators
- Comparison Operators
- Assignment Operators
- Conditional Operators
Arithmetic operators are used to perform mathematical operations between numeric operands. There are seven of them:
+Adds two numeric operands.
-Subtract right operand from the left operand
*Multiply two numeric operands.
/Divide left operand by the right operand.
%Modulus operator. Returns remainder of two operands.
++Increment operator. Increase operand value by one.
--Decrement operator. Decrease value by one.
&&is known as AND operator. It checks whether two operands are non-zero (0, false, undefined, null or "" are considered as zero), if yes then return 1 otherwise 0.
||is known as OR operator. It checks whether any one of the two operands is non-zero (0, false, undefined, null or "" is considered as zero).
!is known as NOT operator. It reverses the boolean result of the operand (or condition).
Comparison operators are used to compare two operands and return Boolean value true or false.
==Compares the equality of two operands without considering type.
===Compares equality of two operands with type.
!=Compares the inequality of two operands.
>Checks whether left-side value is greater than right side value. If yes then returns true otherwise false.
<Checks whether the left operand is less than the right operand. If yes then returns true otherwise false.
>=Checks whether the left operand is greater than or equal to the right operand. If yes then returns true otherwise false.
<=Checks whether the left operand is less than or equal to the right operand. If yes then returns true otherwise false.
Assignment operators are used to assign values to variables.
=Assigns right operand value to left operand.
+=Sums up left and right operand values and assign the result to the left operand.
-=Subtract right operand value from left operand value and assign the result to the left operand.
*=Multiply left and right operand values and assign the result to the left operand.
/=Divide left operand value by right operand value and assign the result to the left operand.
%=Get the modulus of left operand divide by the right operand and assign resulted modulus to the left operand.
Conditional operators are used to compare values, like short if-else condition.
<condition> ? <value1> : <value2>;