Short JavaScript notes and small code examples.

Operators

Cheat sheet
✍️ Arithmetic operators: + - * / %
✍️ Logical operators: || && !
✍️ Bitwise operators: | & ^ ~

Lecture
To solve real-world tasks, you need to perform operations with numbers. In JS, * is multiplication, / is division, and +, - are addition and subtraction. Open browser console and try 2*2, 5-3, 8/4, 6*6. In C++ and Python there are tricky rules around fractional division. In JS, the result is a floating-point number. To round it, use Math.ceil or Math.floor.

To write complex programs that make non-trivial decisions, combine simple logical statements into larger expressions. For example, if we want to determine that x is too small or too large, we combine (x < 4) and (x > 7). Each one is boolean. To combine such expressions, use logical operators: || for OR, && for AND, ! for NOT. So we write (x < 4) || (x > 7).

If you need to pack data into a variable and work at bit level, bitwise operators |, &, ^, ~ are useful. This is a more advanced technique and not something you use every day, but it can help in specific cases.

#education #devJS #devTopic #junior