# Basic Algorithm with Typescript (Part 1)

basic programming for zero experience people

# What is Algorithm ?

In mathematics and computer science field, algorithm is a finite list of instructions given to a computer or we can describe as a finite sequence of computer implementable instructions.

In simple explanation we can say algorithm is list of step to do something / to make something (output).

Every daily basis activities of your life are using the concept of algorithm, for example:

1. How you go to school from your home ?

So, from the picture above we can write a code like this:

`function goToSchool() {  wakeUp();  bath();  cook();  eat();  hopInSchoolBus();  arriveAndLearn();}`

# Basic Logic Syntax in Programming you need to know:

1. Operator
2. Conditional
3. Iteration

## What is Operator ?

An Operator is a symbol / character that determine what action should be performed. There are several operator category that necessary for you:

1. Arithmetic Operators

Arithmetic Operators are operators that perform mathematic calculations. For example, assume we have 2 variables that contain number value:

`let a = 5;let b = 10;// additionconsole.log(a + b) // 15// substractionconsole.log(a - b) // -5// multiplicationconsole.log(a * b) // 50// divisionconsole.log(a / b) // 0.5// modulusconsole.log(a % b) // 5// incrementa++;console.log(a) // 6// decrementb--;console.log(b) // 9`

💡 There are 2 categories of increment / decrement operators. Pre-increment means increment of the variable then save the expression value, on the other hand post-increment means increment of the variable then remember the original value before the increment process.

Pre increment:

`let angka = 10;let res = ++angka;console.log(res); // 11`

Post increment:

`let angka = 10;let res = angka++;console.log(res) // 10`

2. Relational Operators

Relational Operators are operators that evaluate what kind of relationships between 2 value. For example, assume we have 2 variables that contain number value same as number 1:

`let a = 5;let b = 10;// greater thanconsole.log(a > b) // false// lesser thanconsole.log(a < b) // true// greater than or equal toconsole.log(a >= b) // false// lesser than or equal toconsole.log(a <= b) // true// equalityconsole.log(a == b) // false// not equalconsole.log(a != b) // true`

3. Logical Operators

Logical operators are used to combine two or more relational operators. Logical operator will return a boolean value type.

`let a = 5;let b = 10;// ANDconsole.log(a > 5 && b > 10) // false// ORconsole.log(a > 5 || b >= 10) // true// NOTconsole.log(!(a > 5)) // true`

4. Assignment Operators

Assignment operators are used for mathematical calculation and pass the result into a new variable.

`let a = 5;let b = 10;let c = 0;// simple assignmentc = a + b // 15// add assignmentc += a // 5// substract assignmentc -= a // -5// multiply assignmentc *= a // 0// division assignmentc /= a // infinite`

5. Miscellaneous Operators

• Negation operator
`let x = 4;let y = -x;console.log(y) // -4`
• String concat operator

String concat operator used to combined 2 or more string variable

`let message = "hello";let text = " world";console.log(message + text + " again !");// "hello world again !"`
• Typeof operator

Typeof operator is used to return the data type of a variable

`let num = 5;console.log(typeof num) // number`