DevClub - JavaScript Module : Variables

Table of contents

HTML/JavaScript program that uses the contents of this module.

Encoder/Decoder:

Encode your text using a password and decode it back.

It uses bitwise operations to encode and decode a string, based on a password.

Lesson 00 - Script Declaration

<script src="scripts.js" defer></script>

The defer attribute makes the script load after the HTML is parsed, preventing render-blocking and improving page load performance.

Lesson 01 - Variables

Variables are containers for storing values, JS does NOT enforce typing.

Lesson 02 - Strings

Strings a sequence(Vector) of characters(char) values.
They can be declared by:

Lessonh23 - Numbers

Numbers in JavaScript are all 64-bit floating-point values, independently of their type.

Lesson 04 - Booleans

Booleans can be two values: true or false.

They can be representing not only by using true/false, but also by using 1/0, null, or undefined.

Lesson Extra - Binary Operations & Bitshift

Bitwise operators work on 32-bit integers, performing operations at the binary level.

Binary Operations

Bitshift

OBS:
the difference between >> and >>> is how they handle the sign bit for negative numbers.
>> preserves the sign bit, while >>> does not, filling with zeros regardless of the sign.
Example: -5 >> 1 = -3, -5 >>> 1 = 2147483645
in binary: -5 >> 1 = 11111101, -5 >>> 1 = 01111101

Lesson 05 - Objects

Objects are collections of key-value pairs, where the keys are strings and the values can be of any type.

Example of an object:

const person = {
    name: "Harry Potter",
    age: 12,
    canDrive: false,
    hobbies: ["owls", "defense against the dark arts", "quidditch"],
    address: {
        street: "4 Privet Drive",
        city: "Little Whinging",
        country: "England",
        obs: "The door under the stairs"
    }
};

Lesson 06 - Null h2d Undefined

null represents the intentional absence of any object value.

undefined represents the absence of a value or an uninitialized variable.

OBS: Both null and undefined return false in a boolean context.

Lesson 07 - Arrays

Arrays are ordered collections of values, which can be of any type. And the first element starts at 0.

Example:

const fruits = ["apple", "banana", "cherry"];

fruits[0] → "apple"

Lesson 08 - If and Else

Conditional statements allowing you to execute different blocks of code based on certain conditions.

Lesson 09 - Functions

Functions are reusable blocks of code that perform a specific task. They can be defined using function declarations or function expressions.

Example of a function declaration:

function greet(name) {
    return `Hello, ${name}!`;
}

Example of a function expression:

const greet = function(name) {
    return `Hello, ${name}!`;
};

Example of an arrow function:

const greet = (name) => {
    return `Hello, ${name}!`;
};

Or even more concise:

const greet = name => `Hello, ${name}!`;
OBS: Arrow functions have a shorter syntax and do not have their own this context, making them useful for certain situations, such as when working with callbacks or methods that require a specific this value.

Wrong!

const person = {
    name: "Harry",
    greet: () => `Hello, ${this.name}`
};

Right!

const person = {
    name: "Harry",
    greet() {
        return `Hello, ${this.name}`;
    }
};