JavaScript Operations

Random Number Generator

Lesson 14 - Math()

Basic Arithmetic and Logical Operations

Lesson 15 - random()

Random number generation

Lesson 16 - Arithmetic Operations

Note:
The increment (++) and decrement (--) operators can be used as prefix and postfix.

Prefix: (++x or --x), the variable is modified before its value is used in an expression.
Postfix: (x++ or x--), the variable value is used in the expression before it is modified.

Lesson 17 - Atribuition Operations

Lesson 18 - Comparison Operations

Note:

The difference between loose (==) and strict (===) equality is that strict equality checks the type as well as the value.

For example, 5 == '5' is true because the string '5' is parsed to the number 5, but 5 === '5' is false because they are of different types.

Lesson 19 - Logical Operations

Lesson 20 - typeof and delete

Lesson 21 - Else IF

Conditional statements


Lesson 22 - Ternary Operator

The ternary operator is a shorthand for an if-else statement. It takes three operands: a condition, an expression to execute if the condition is true, and an expression to execute if the condition is false.

condition ? expressionIfTrue : expressionIfFalse;

If you want only the if statement without an else, you can use the ternary operator with an empty expression for the false case.

condition ? expressionIfTrue : null;
or
condition && expressionIfTrue;

In the second example, if the condition is true, the expression will be executed. If the condition is false, the expression will not be executed, and the result will be false.

Lesson 23 - Switch Statement

The switch statement is used to perform different actions based on different conditions.

switch (expression) {
    case value1:
        // code to be executed if expression === value1
        break;
    case value2:
        // code to be executed if expression === value2
        break;
    default:
        // code to be executed if expression doesn't match any case
}

Lesson 24 - Timeout and Interval

The setTimeout function is used to execute a function after a specified delay, while setInterval is used to execute a function repeatedly at specified intervals.

setTimeout(function, delay);
setInterval(function, interval);

Both functions return a unique identifier that can be used to cancel the timeout or interval using clearTimeout or clearInterval.

// Example of setTimeout
const timeoutId = setTimeout(() => {
    console.log('This will be logged after 2 seconds');
}, 2000);

// Example of setInterval
const intervalId = setInterval(() => {
    console.log('This will be logged every 2 seconds');
}, 2000);

// To cancel the timeout
clearTimeout(timeoutId);
// To cancel the interval
clearInterval(intervalId);
it works with by calling

Project 04 - Coin Converter

Live Site