Learn JavaScript

023 - Number

Number

Double Precision (recherche internet) Syntactic Sugar "_" .

console.log(1000000); // "1000000"
    console.log(1_000_000);  // "1000000"
    console.log(1e6);  // "9007199254740991"
    console.log(10 ** 6);  // "9007199254740991"
    console.log(1000000.0); 
    

e ** With Decimal Number Min Value

Number.MAX_SAFE_INTEGER // "9007199254740991"
    

Number Max Value

Number.MAX_VALUE // "1.7976931348623157e+308";
    Number.MAX_VALUE + 2035 = Number.MAX_VALUE // "Number.MAX_VALUE"
    

024 - Number Methodes

025 Math Object

Les méthodes du objet Math

  • Math.abs() \(|x|\)
    retourne la valeur absolue d'un nombre.
  • Math.acos() \(\arccos(x)\)
    retourne l'arc cosinus d'un nombre.
  • Math.acosh() \(\operatorname{arcosh}(x)\)
    retourne l'arc cosinus hyperbolique d'un nombre.
  • Math.acot() \(\operatorname{arccot}(x)\)
    retourne l'arc cotangente d'un nombre.
  • Math.acoth() \(\operatorname{arccoth}(x)\)
    retourne l'arc cotangente hyperbolique d'un nombre.
  • Math.atan() \(\arctan(x)\)
    retourne l'arc tangente d'un nombre.
  • Math.atan2() \(\arctan2(y, x)\)
    retourne l'arc tangente d'un nombre.
  • Math.atanh() \(\operatorname{artanh}(x)\)
    retourne l'arc tangente hyperbolique d'un nombre.
  • Math.cosh() \(\operatorname{cosh}(x)\)
    retourne le cosinus hyperbolique d'un nombre.
  • Math.max() \(\max(x_1, x_2, \ldots, x_n)\)
    retourne le plus grand des nombres fournis.
  • Math.min() \(\min(x_1, x_2, \ldots, x_n)\)
    retourne le plus petit des nombres fournis.
  • Math.pow() \((x^y)\)
    retourne un nombre élevé à la puissance d'un autre nombre.
  • Math.random() \(\operatorname{random}()\)
    retourne un nombre pseudo-aléatoire entre 0 et 1.
  • Math.round() \(\operatorname{round}(x)\)
    retourne le nombre arrondi à l'entier le plus proche.
  • Math.sign() \(\operatorname{sign}(x)\)
    retourne le signe d'un nombre, indiquant s'il est positif, négatif ou zéro.
  • Math.sinh() \(\operatorname{sinh}(x)\)
    retourne le sinus hyperbolique d'un nombre.
  • Math.sqrt() \(\sqrt{x}\)
    retourne la racine carrée d'un nombre.
  • Math.tan() \(\tan(x)\)
    retourne la tangente d'un nombre. \(\tan(x)\)
  • Math.tanh() \(\operatorname{tanh}(x)\)
    retourne la tangente hyperbolique d'un nombre. \(\operatorname{tanh}(x)\)
  • Math.trunc() \(\operatorname{trunc}(x)\)
    retourne la partie entière d'un nombre.
Math.round(99.2); // 99
Math.round(99.5); // 100

Math.ceil(99.2); // 100 
Math.floor(99.9); // 99


Math.min(10, 20, 100, -100, 90); // -100
Math.max(10, 20, 100, -100, 90); // 100


Math.random(); // aliatoire

Math.trunc(99.5); // 99
Math.trunc(99.99); // 99

Objets natifs

Propriétés de valeur

  • globalThis
  • Infinity
  • NaN
  • undefined

Propriétés de fonction

  • eval()
  • isFinite()
  • isNaN()

Propriétés de fonction

  • parseFloat()
  • parseInt()
  • decodeURI()
  • decodeURIComponent()
  • encodeURI()
  • encodeURIComponent()
  • escape() Obsolète
  • unescape() Obsolète

Objets fondamentaux

  • Object
  • Function
  • Boolean
  • Symbol

Objets d'erreur

  • Error
  • AggregateError
  • EvalError
  • RangeError
  • ReferenceError
  • SuppressedError
  • SyntaxError
  • TypeError
  • URIError
  • InternalError Non standard

Nombres et dates

  • Number
  • BigInt
  • Math
  • Date
  • Temporal

Traitement du texte

  • String
  • RegExp

Collections indexées

  • Array
  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • BigInt64Array
  • BigUint64Array
  • Float16Array
  • Float32Array
  • Float64Array

Collections avec clés

  • Map
  • Set
  • WeakMap
  • WeakSet

Données structurées

  • ArrayBuffer
  • SharedArrayBuffer
  • DataView
  • Atomics

JSON

  • JSON

Gestion de la mémoire

  • WeakRef
  • FinalizationRegistry

Abstraction du contrôle

  • Iterator
  • AsyncIterator
  • Promise
  • GeneratorFunction
  • AsyncGeneratorFunction
  • Generator
  • AsyncGenerator
  • AsyncFunction
  • DisposableStack
  • AsyncDisposableStack
  • Réflexion
  • Reflect
  • Proxy
  • Internationalisation
  • Intl
  • Intl.Collator
  • Intl.DateTimeFormat
  • Intl.DisplayNames
  • Intl.DurationFormat
  • Intl.ListFormat
  • Intl.Locale
  • Intl.NumberFormat
  • Intl.PluralRules
  • Intl.RelativeTimeFormat
  • Intl.Segmenter
  • Instructions

Instructions et déclarations JavaScript

Contrôle du flux d'exécution

  • return
  • break
  • continue
  • throw
  • if...else
  • switch
  • try...catch

Déclarations de variables

  • var
  • let
  • const
  • using
  • await using

Fonctions et classes

  • function
  • function*
  • async function
  • async function*
  • class

Itérations

  • do...while
  • for
  • for...in
  • for...of
  • for await...of
  • while
  • Autres
  • Vide
  • Bloc
  • Instruction d'expression
  • debugger
  • export
  • import
  • label
  • with Obsolète

Expressions et opérateurs

Expressions et opérateurs JavaScript.

Expressions primaires

  • this
  • Litéraux
  • []
  • {}

Function

  • function
  • class
  • function*
  • async function
  • async function*
  • /ab+c/i
  • `string`
  • ( )

Expressions vers la gauche

  • Accesseurs de propriété
  • ?.
  • new
  • new.target
  • import.meta
  • super
  • import()

Increment & decrement

  • A++
  • A--
  • ++A
  • --A

Opérateurs unaires

  • +
  • -
  • ~
  • !
  • await

Opérateurs arithmétiques

  • **
  • *
  • /
  • %
  • + (Plus)
  • -
  • ~
  • !

await

Opérateurs arithmétiques

  • **
  • *
  • /
  • %
  • + (Plus)
  • -
  • ~
  • !

await

Opérateurs arithmétiques

  • **
  • *
  • /
  • %
  • + (Plus)
  • -
  • ~
  • !

await

Opérateurs arithmétiques

  • **
  • *
  • /
  • %
  • + (Plus)
  • -
  • ~
  • !
  • await

Opérateurs d'égalité

  • ==
  • !=
  • ===
  • !==

Opérateurs de décalage binaire

  • <<
  • >>
  • >>>

Opérateurs logiques binaires

  • &
  • |
  • ^

Opérateurs logiques

  • &&
  • ||
  • ??

Opérateur conditionnel (opérateur ternaire)

(condition ? ifTrue : ifFalse)

Opérateurs d'affectation

  • =
  • *=
  • /=
  • %=
  • +=
  • -=
  • <<=
  • >>=
  • >>>=
  • &=
  • ^=
  • |=
  • **=
  • &&=
  • ||=
  • ??=
  • {a, b} = {a:1, b:2}

Opérateurs de génération

  • yield
  • yield*

Syntaxe de déploiement

  • ...obj

Opérateur virgule

,

Fonctions

Les fonctions JavaScript

Fonctions fléchées

Paramètres par défaut

  • Paramètres rest
  • arguments
  • Définitions de méthodes
  • Accesseur
  • Mutateur

Classes

Classes JavaScript

  • constructor
  • extends
  • Éléments privés
  • Champs de classe publics
  • static
  • Blocs d'initialisation statique
  • Expressions régulières
  • Expressions régulières JavaScript

27 - String Methods

Access With Index Access With charAt() length trim() => remove espace toUpperCase() toLowerCase() Chain Methods

let theName = "  Ahmed  ";

theName; // "  Ahmed  "
theName[5]; // m

theName.trim(); // Ahmed
// Chain Methods
theName.trim().charAt(5).toUpperCase()

String Methods

indexOf(Value [Mand], Start[Opt] 0)

let a = "Elzero Web School";

a.indexOf("Web") // 7
a.indexOf("Web", 8) // -1

lastIndexOf(Value [Mand], Start [Opt] length) slice(Start [MAnd], End [Opt] Not Include End) repeat(Times) [ES6] split(Separator [Opt], limit [Opt])

040 - Array Big Introduction

Arrays

Create Arrys [To w Methods] new Array()

let myFriends = ["Ahmed", "Mohamed", "Sayed"];

042 - Add And Remove From Array

Array Methods [Adding And Removing]

unshift("", "", ...) Add Element To The First push("", "", ...) Add Element To The End shift() Relove First Element From Array pop() Remove Last Element From Array

066 - Arrow Function Syntax

Arrow Function

071 - Higher Order Functions - Map

Higher Order Function

is a function that accepts functions as parameters and/or returns a function.

Map

method creates a new array populated with the resultes of calling a provided function on every element. in the calling array. Syntax map(callBackFunction(Element, Index, Array){}, thisArg) Element => The current element beig processed in the array. Index => The index of the current element being processed in the array. Array => The Current Array Notes Map Return A New Array Examples Anonymous Function Named Function

let Arry = [1, 2, 3, 4];

console.log(Arry);

let NewArry = [];

for (let i = 0; i < Arry.length; i++){
    NewArry.push(Arry[i] + Arry[i] )
};

console.log(NewArry);

let addSelf = myNums.map(function(element, index, arr){
    console.log(`Current Element => ${element}`);
    console.log(`Current Index => ${index}`);
    console.log(`Array => ${arr}`);
    console.log(`This => ${this}`);
    // return element + element;
}, 10);

let addSelf = myNums.map((e)=> e + e)
console.log(addSelf);

funxtion   addition(ele) {
    return ele + ele;
}

let add = myNums.map(addition);

console.log(add);

074 Higher Order Functions - Filter

Filter

Filter Longest Word By Number

let sentence = "I Love Food Code Too Playing Much";

let smallWords = sentence.split(" ").filter(function(ele){
    return ele.length <= 4;
}).join(" ");

// Ignore Numbers
let ignoreNumbers = "Elz123er4o";

let ign = ignoreNumbers

090 - Product With Title And Description

DOM [Create Elements]

let myMainElement = document.createElement("div");
let myHeading = document.createElement("h2");
let lyParagraph = document.createElement("p");

let myHeadingText = document.createTextNode("Product");
let myParagraphText = document.createTextNode("Product");

Add Heading text

myHeading.appendChild(myHeadingText);

Add Heading To Main Element

myMainElement.appendChild(myHeading);

Add Paragraph Text

myParagraph.appendChild(myParagraphText);

091 - Deal With Children's

let myElemµent = document.querySelector("div");

console.log(myElement.children); \\ 
console.log(myElement.children[0]); \\
console.log(myElement.childNodes); \\

093 - Validate Form And Prevent Default

DOM [Events]

 let userInput = document.querySelector("[name='username']");
 let ageInput = document.querySelector("[name='age']");

 document.forms[0].onsubmt = function (e) {
    let userValid = false;
    let ageValid = false;

    if(userInput.value !== "" && userInput.value.length <= 10){
        userValid = true;
    };

    if(ageInput.value !== ""){
        ageValid = true;
    }
    if (userValid === false || ageValid === false){
        e.preventDefault();
    }
 }

094 - Event Simulation Click Focus Blur

DOM [Events Simulation]

let two = document.querySelector(".two");

window.onload = function (){
    tow.focus();
};

cersur sorte input

let one = document.querySelector(".one");

one.onblur = function (){
    document.links[0].click();
}

095 - Class List Object And Methods

DOM [Class List]

classList -length -contains -item(index) -add -remove -toggle

HTML

<div id="my-div" class="one two show test">Div With Many Classes</div>

JavaScrept:

let element = document.getElementById("my-div");

element.classList //  DOMTokenlist(4)["one", "two", "show", "test", value: "one two shw test"]
typeof element.classList // Object
element.classList.contains("osama"); // false
element.classList.contains("two"); // true
element.classList.item("3"); // shw

115 - Destructuring Arrays

Destructuring: is a JavaScript experession that allows us to extract data from arrays, objects, and maps and set them into new, distinct variables.

let a = 1;
let b = 2;
let c = 3;

let myFriends = ["Ahmed", "Sayed", "Ali"];

[a = "A", b, c] = myFriend;

console.log(a) // Ahmed
console.log(b) // Sayed
console.log(c) // Ali

let [x, y, z] = myFriend;

console.log(x) // Ahmed
console.log(y) // Sayed
console.log(z) // Ali

let [, k,];

console.log(k) // Sayed

Advanced Examples

let myFriends = ["Ahmed", "Sayed", "Ali", ["Shady", "Amr", ["Mohamed", "Gamal"]]];

myFriends[3][2][1]; // Gamal

let [, , , [a, , [, b]]] = myFriends;

console.log(a); // Shady
console.log(b); // Gamal

Destructuring Array => Swapping Variables

let book = "video";
let video = "Book";

[book, video] = [video, book];

console.log(book); // Book
console.log(video); // Video

Destructuring Object

const user = {
    theName: "Osama",
    theAge: 39,
    theTitle: "Developer",
    theCountry: "Egypt"
};

118 - Destructuring Objects

const user = {
    theName: "Osama",
    theAge: 39,
    theTitle: "Developer",
    theCountry: "Egypt",
    skills: {
        html: 70,
        css: 80,
    }
};

console.log(user.theName); // Osama 

({theName, theAge, theTitle, theContry } = user);
//_____________
const {
    theName: x, 
    theAge: a, 
    theTitle = "undif", 
    theContry: k = "tunis",
    skills: {html: h, css}
} = user;

console.log(x); // Osama
console.log(k); // Egypt
console.log(h); // 70
console.log(css): // 80


const {html: skillOne, css: skillTwo} = user.skills;

123 Set Data Types And Methods

Set Data Type

Santax: new Set(Iterable).

Object To Store Unique Values. Cannot Access Elements By Index Properties: siez Methods add delete

let myData = [1, 1, 1, 2, 3]; // [1, 1, 1, 2, 3]
let myUniqueData = new Set([1, 1, 2, 3]); // {1, 1, 1, 2, 3}
let myUniqueData = new Set(myData);
let myUniqueData = new Set(myData);

124 - Set vs WeakSet And Garbage Collecto

Set vs WeakSet

The WeakSet is weak, meaning references to objects in a WeakSet are held weakly. If no other references to an object stored in the WeakSet exist, those objects can be garbage collected.

129 - Array.copyWithin Method

Array Methods

Array.copyWithin(Target, Start => Optional, End => Optional) "Copy Part Of An Array To Another Location in The Same Array"

Any Negative Value Will Count From The End Target

Index To Copy Part To If At Or Greater Than Array Length Nothing Will Be Copied Start Index To Start copying From If Ommited = Start From Index 0 End Index To End Copyinf From Not Including End If Ommited = Reach The End

148 - Constructor Function Introduction

syntaxe: exempl

function User(id, username, salary){
    this.id = id;
    this.u = username;
    this.s = salary + 1000;
};

let userOne = new User(100, "Hassan", 5000);
let userTwo = new User(100, "Hassan", 5000);
let userThree7  = new User(100, "Hassan", 5000);

userOne.id // 100 
userOne.u // Hassan

ES 2015

class User {
    constructor(id, username, salary){
        this.i = id;
        this.u = username;
        this.s = salary;
    }
}

instanceof

userOne = new User(100, "Elzero", 5000);

userOne instanceof User // true
userOne.constructor === User // true

150 - Deal With Properties And Methods

exemple:

class User {
    constructor(id, username, salary){
        // Propreties
        this.i = id;
        this.u = username || "Unknown";
        this.s = salary < 6000 ? salary + 500 : salary;
        this.msg = function(){
            return `Hello ${this.u} Your Salary Is ${this.s}`;
        };
    }
    // Methods
    writeMsg(){
        return `Hello ${this.u} Your Salary Is ${this.s}`;
    }
}

let userOne = new User(100, "Elzero", 500);
let userTwo = new User(101, "Ahmed", 6000);

userOne.u //
userOne.s //

userTwo.u //
userTwo.s //

151 - Update Properties And Built In Cons

constructor Function

class User {
    constructor(id, username, salary){
        this.i = id;
        this.u = username;
        this.s = salary;
    }
    updateName(newName){
        this.u = newName;
    }
}

let userOne = new User(100, "Elzero", 5000);

userOne.u // Elzero
userOne.updateName("Osama");
userOne.u // Osama

let strOne = "Elzero";
let strTwo = new String("Elzero");

typeof strOne // String
typeof strTwp // Object

strOne instanceof String // fauls
strTwo instanceof String // true

strOne.constructor === String // true
strTwo.constructor === String // true

152 - Class Static Properties And Methods

Class

static Properties And Methods

class User {
    // Static Property
    static cont = 0;

    constructor(id, username, salary){
        this.i = id;
        this.u = username;
        this.s = salary;
        User.cont++;
    }
    // Static Methods
    static syHello(){
        return `Hello From Class`;
    }
    static contMembers(){
        return `${this.cont}`
    }
}

153 - Class Inheritance

Class

Inheritance

class  User {
    constructor(id, username){
        this.i = id;
        this.u = username;
    };
    sayHello(){
        return `Hello ${this.u}`;
    }
}

// Derived Class
class Admin extends User {
    constructor(id, username, permissions){
        super(id, username);
        this.p = permissions;
    }
}

class Superman extends Admin {
    constructor(id, username, permisson, ability){
        super(id, username, permissions);
        this.a = ability
    }
}

154 - Class Encapsulation

Encapsulation

class User {
    // Provate Property
    #e;
    constructor(id, username, eSalary){
        this.i = id;
        this.u = username;
        this.#e = eSalaey;
    }
    getSalary(){
        return parseInt(this.#e);
    }
}

let userOne = new User(100, "Elzero", "5OO dt");

userOne.u // 
userOne.getSalary() * 0.3 //

155 - Prototype Introduction

Prototype

class User {
    constructor(id, username){
        this.i = id;
        this.u = username;
    }
    sayHello(){
        return `Hello ${this.u}`;
    }
}
let userOne = new User(100, "Elziro");

userOne.u // Elziro

User.prototype;

let strOne = "Elzero";

String.prototype;

167 - Modules Import And Export

    <script src="js/ymain.js" type="module"></script>
    <script src="js/app.js" type="module"></script>

main.js

Export Methode 1

    export let a = 10;
    export let arr = [1, 2, 3, 4];

    export function saySomething(){
        return `Something`;
    }

Export Methode 2

    let a = 10;
    let arr = [1, 2, 3, 4];

    function saySomething(){
        return `Something`;
    }

    export { a, arr, saySomething };

app.js

    import {a, arr, saySomething as s} from "js/main.js";

    console.log(a); // 10
    console.log(arr); // [1, 2, 3, 4]
    console.log(s()); // Something

Export Alias Named Export Import All

main.js

    export default function sayHello(){
         return `Hello`;
    }

app.js

    import elzero, { a, arr, saySomething } from from "js/main.js";

    console.log(elzero()); //  Hello

Export Methode 2

    export default function(){
         return `Hello`;
    }

Impore All

    import * as all from from "js/main.js";

    console.log(all.arr); // [1, 2, 3, 4]
    console.log(all.saySomething); // Something

169 - What Is JSON

Whate Is JSON ?

Why JSON ?

JSON vs XML
Text Based Format = Markup Lang age
Lightweight Heavier
Does Not Use Tags Using Tags
Shorter Not Short
Can Use Arrays Cannot Use Arrays
Not Support Comments Support Comments

170 - JSON Syntax And Compare With Js Object

JSON Syntax

Available Data Types

Exemple :

{
    "string": "Elzero",
    "number": 100,
    "object": {
        "EG": "Giza",
        "KSA": "Riyadh"
    },
    "array": ["HTML", "CSS", "JS"],
    "Boolean": true,
    "null": null
}

172 - Parse And Stringify

const myJsonObjectFromServer = '{"Username": "Osama", "Age": 39}';
console.log(typeof myJsonObjectFromServer); // string
console.log(myJsonObjectFromServer); // {"Username": "Osama", "Age": 39}

const myJsObject = JSON.parse(myJsonObjectFromServer);
console.log(typeof myJsObject); // object
console.log(myJsObject); // -> {Username: 'Osama', Age: 39} 

myJsObject["Username"] = "Elzero";
myJsObject["Age"] = 40;

const myJsonObjectToServer = JSON.stringify(myJsObject);
console.log(typeof myJsonObjectToServer); // string
console.log(myJsonObjectToServer); // -> {Username: 'Elzero', Age: 40}

173 - Asynchronous

To Understand Ajax, Fetch, Promises

Asynchronous VS Synchronous Programming

Synchronous

Asynchronous

Search

174 - Call Stack And Web API

To Understand Ajax, Fetch, Promises

Call Stack || Stack Trace

Web API


setTimeout(()=>{
    console.log("Web API")
}, 0);

function one(){
    console.log("One");
}
function two(){
    one();
    console.log("Two");
}
function three(){
    tow();
    console.log("Three")
}

three()
/* 
One
Two
Three
Web API
*/

176 - What Is AJAX And Network Informatio

AJAX

Test new XMLHttpRequest(); Request And Response Status Code

let req = new XMLHtpRequest();
console.log(req);

177 - Request And Response From Real API

Ajax Ready State => Status Of The Request

consol.log('hello');

THe End.