Aller au contenu

JavaScript

Si Wikipedia, tasanayt tilellit.
JavaScript
langage de script (fr) Suqel, langage de programmation orienté prototype (fr) Suqel, langage impératif (fr) Suqel, langage de programmation fonctionnel (fr) Suqel, langage de programmation événementielle (fr) Suqel, plateforme informatique (fr) Suqel, langage interprété (fr) Suqel, langage de programmation multi-paradigme (fr) Suqel, tutlayt n usihel, langage de programmation stricte (fr) Suqel, langage de haut niveau (fr) Suqel, Programmation orientée prototype (fr) Suqel, généricité (fr) Suqel, programmation fonctionnelle (fr) Suqel, programmation impérative (fr) Suqel, Programmation orientée aspect (fr) Suqel d programmation événementielle (fr) Suqel
Isefka
Azemz n ubeddi d unulfu 4 Duǧember 1995
Asemres programmation (fr) Suqel d programmation web (fr) Suqel
Isem aẓaran JavaScript
Yettusemma ɣef Java (tutlayt)
Imlan Sun Microsystems (fr) Suqel d Oracle (fr) Suqel
Yeska ɣef ECMAScript (fr) Suqel
Imeddez LiveScript (fr) Suqel
Azemz n usuffeɣ Ctember 1995
Régi par (fr) Suqel Ecma International (fr) Suqel
Conçu par (fr) Suqel Brendan Eich (fr) Suqel
Identifiant de version logicielle (fr) Suqel ECMAScript 2024, ECMAScript 2025, ECMAScript 7, ECMAScript 6, ECMAScript 5.1, ECMAScript 2017, ECMAScript 2018, ECMAScript 2019, ECMAScript 2020, ECMAScript 2021, ECMAScript 2022 d ECMAScript 2023
Asmel web unṣib ecma-international.org…
Aglam deg URL tapor.ca…, marketplace.sshopencloud.eu… d consumerrights.wiki…
Hashtag (mul) Suqel Javascript
Type MIME (fr) Suqel text/javascript, application/x-ecmascript, application/x-javascript, text/javascript1.0, text/javascript1.1, text/javascript1.2, text/javascript1.4, text/javascript1.3, text/javascript1.5, text/livescript, text/x-ecmascript d text/x-javascript
Système de typage (fr) Suqel typage dynamique (fr) Suqel, Duck typing (fr) Suqel d Programmation orientée prototype (fr) Suqel
Date d'annonce publique (fr) Suqel 4 Duǧember 1995
Extension de fichier (fr) Suqel js d mjs

JavaScript d tutlayt n usihel mebla aefsu(Tameslayt tasuɣlant) i d-yesnulfa Brendan Eich (Netscape). JavaScript itddu kan deg yiminig web maca tura nezmer ad t-nesseqdec deg tama n uqeddac(Backend) s Node.js.

Tameslayt n usihel JavaScript tella d yiwet seg tmeslayin yettwasxedmen aṭas deg umaḍal n tsenselkimt. Seg wasmi i d-tlul deg useggas n 1995, teqqel d taɣawsa tagejdant deg usnerni n Web. Ass-a, ur tettwaḥseb ara kan d tameslayt n yisebtar n Web, wanag tettwasxedem daɣen deg usihel n yiqeddacen, n yisnasen izirazen, d kran n yisnasen n tnarit, d waṭas n yiḥricen-nniḍen.

2. Amazray

[ẓreg | ẓreg aɣbalu]

2.1. Talalit n JavaScript

[ẓreg | ẓreg aɣbalu]

JavaScript tlul-d deg useggas n 1995, mi i tt-yesnulfa Brendan Eich deg tkebbanit Netscape Communications. Deg tazwara, isem-is yella "Mocha", sakkin yuɣal "LiveScript", qbel ad yettusema "JavaScript". Iswi amezwaru-is yella ad d-yefk i yimsidag n Web allal n usihel asdawan (interactif) deg yisebtar n Web.

Brendan Eich yesnulfa-d lqem amezwaru n tmeslayt-a deg 10 n wussan kan.

Mocha: D wawal amezwaru i yettunefken i tmeslayt-a.

LiveScript: Sakkin, isem-a yuɣal d LiveScript deg wamber (beta) n yiminig.

JavaScript: Deg dujember 1995, isem yuɣal d JavaScript. Abeddel-a n yisem yella-d s tmuɣli n udellel (marketing), acku deg tallit-nni, tameslayt n usihel Java tella tettwassen aṭas yerna tesɛa azal ameqqran. Netscape tebɣa ad tesqedcec tagnit n Java, ɣas ma JavaScript ur yesɛi ara assaɣ atrar akked Java.

Amgaru n Yiminigen d Usdul n ECMAScript (1996-1999)

[ẓreg | ẓreg aɣbalu]

Mi i twala takebbanit Microsoft d akken JavaScript yuɣal d axatar, tesnulfa-d lqem-is i yiminig-is Internet Explorer, isem-is JScript. Aya yesnulfa "Amgaru n Yiminigen", anda yal iminig yesɛa tameslayt-is, d ayen i yesserwen imsihlen (Ineflayen) acku tangalt ur telli ara txeddem akken iwata deg yiminigen meṛṛa.

I wakken ad frun ugur-a, Netscape tefka tameslayt-a i tuddma Ecma International i wakken ad tt-slugen (tizeɣt).

1997 (ES1): Alugen amezwaru ECMA-262 yeffɣ-d s yisem ECMAScript 1.

1998 (ES2): Asnerni meẓẓiyen i uḍfar n ISO/IEC.

1999 (ES3): Lqem-a yella d axatar aṭas, yerna-d Regular Expressions (tinfaliyin tiluganin), try/catch i usefrek n tuccḍiwin, d usbadu ifazen n tɣawsiwin. Lqem-a yeqqim d amud amezwaru n JavaScript i waṭas n yiseggasen.

Tallit n "Web 2.0" d Ajax (2000-2008)

[ẓreg | ẓreg aɣbalu]

Deg tazwara n yiseggasen n 2000, JavaScript ur yettwaqadar ara aṭas, yella kan i usihel n yimussuyen (Amray/Merru) d yisebtar fessusen. Maca, tallit n Web 2.0 tbeddel kulci.

Asnas n Ajax (Asynchronous JavaScript and XML) yefka i yimsihlen tizemmar ad selḥun isefka seg uqeddac war ma alsen asali n usebter. Isnasen am Gmail (2004) d Google Maps (2005) sbegnen-d d akken JavaScript yezmer ad isali isnasen n Web ixanzen d isdawanen.

Deg tallit-a, tlul jQuery (2006), d tamkarḍit i yessifsen asihel n DOM yerna tefru uguren n umgaru gar yiminigen.

2009 (ES5): Ecma tefka lqem ES5, i d-yernan JSON s wudem unṣib, Array.prototype.map/filter, d uskar strict mode i uḍman n tɣellist n tengalt.

Tawri n Node.js: JavaScript yeffeɣ seg Yiminig (2009)

[ẓreg | ẓreg aɣbalu]

Aseggas n 2009 yella d tagrawla deg umezruy n JavaScript. Amsihel Ryan Dahl yesnulfa Node.js, s useqdec n umutur V8 n Google Chrome.

Aya yefka i JavaScript tizemmar ad ixeddem deg tama uqeddac (backend), mačči kan deg yiminig (frontend). Seg imir-nni, JavaScript tuɣal d tameslayt "Full-Stack", anda amsihel yezmer ad iseqdec yiwet n tutlayt i yisebtar n Web, i yiqeddacen, d yizdaren(affiwin)n n yisefka.

Tagrawla n ES6 / ES2015 d Ukatar n yimahilen (Frameworks)

[ẓreg | ẓreg aɣbalu]

Deg useggas n 2015, Ecma tefka lqem ameqqran akk deg umezruy n tmeslayt-a: ECMAScript 2015 (ES6). Seg wass-a, alugen yuɣal yettbeddel yal aseggas (ES2016, ES2017, ...).

ES6 yerna tiseddast tatrarin i yerran asihel yeshel yerna iqud:

let d const i usefrek n telqeyt (scope).

Tiseɣnin s uaneccab (Arrow functions =>).

Tiserkemt i usihel yuɣden ar tɣawsa.

Lweɛd (Promises) i usefrek n usihel aramtawan (asynchrone).

Izegrar kter/sifeḍ.

Deg tallit-a daɣen, akatar n yimahilen (frameworks) am React (Facebook, 2013), Angular (Google), d Vue.js beddelen amek i ttwasalnen yisnasen n Web, s useqdec n yimudam am "Virtual DOM" d "Composants".

Tallit Tatrart: TypeScript, WebAssembly d Tigzi Taragmawant (2018-Ass-a)

[ẓreg | ẓreg aɣbalu]

Ma d ass-a, JavaScript ur yesɛi ara tilas. Amhaz-is yekcem deg waṭas n yiḥricen:

TypeScript: Tameslayt i d-tesnulfa Microsoft i yernan tawsit n isefka (typage statique) i JavaScript. Ass-a, tuget n yisnasen imeqqranen ttwagen s TypeScript i uḍman n tɣellist d tmellet n tengalt.

WebAssembly (Wasm): Yefka tizemmar i yimsihlen ad selkmen tangalt (C++, Rust) deg yiminig s urured iqerben ar iseɣẓanen n tnarit yettwarun s C/C++ (natif), yettwasqdec s umata i yisnasen izuyaz (am uraren) d usihel aẓayan.

Tigzi Taragmawant : S tmkarḍiyin am TensorFlow.js, JavaScript yuɣal yezmer ad iselkem timudmiwin n tigzi taragmawant srid deg yiminig, war ma yuzen isefka ar uqeddac, d ayen ara yemmestnen tudert tusligt.

Isnasen Izirazen d Tnarit: S React Native d Electron, JavaScript ass-a yessalay isnasen i tilifunat (iOS/Android) d yiselkimen n tnarit (am VS Code akked Discord).

2.2. Alugen ECMAScript

[ẓreg | ẓreg aɣbalu]

Deg useggas n 1997, JavaScript tuɣal d alugen n Ecma International s yisem "ECMAScript". Seg imir-nni, tameslayt-a tettwasnerni s waṭas n ileqman:

  • ECMAScript 1 (1997): Alugen amezwaru.
  • ECMAScript 3 (1999): Timerna n wallalen n usenqed n tuccḍiwin, Tinfaliyin tiluganin (regular expressions).
  • ECMAScript 5 (2009): Asemdu n JSON, asemdu n tɣawsa "strict mode".
  • ECMAScript 6 / ES2015 (2015): Timerna tameqqrant: let, const, class, Promise, arrow functions, modules.
  • ECMAScript 2020+: Timerna n BigInt, Optional Chaining, Nullish Coalescing.

2.3. Imeslayen n usihel yeqqnen ar JavaScript

[ẓreg | ẓreg aɣbalu]

Aṭas n tmeslayin-nniḍen n usihel bnant ɣef JavaScript neɣ ttwasuqlent ar JavaScript:

TypeScript: Tameslayt n usihel s tewsit n isefka (typed) i d-yesnulfa Microsoft.

CoffeeScript: Tameslayt yettwasuqlen ar JavaScript s tseddast ifessusen.

Dart: Tameslayt n usihel i d-yesnulfa Google, tettwasxedem deg Flutter.

3. Taseddast d Umawal

[ẓreg | ẓreg aɣbalu]

3.1. Tawsit n tmeslayt

[ẓreg | ẓreg aɣbalu]

JavaScript d tameslayt:

Tasuɣlant: Ur teḥwaǧ ara asefsu send aselkem. Amessuɣal iqqar-d tangalt srid.

S tawsit asmussaw: Tawsit n umutti tettubeddel deg wakud n uselkem.

Agetkalmaḍ (multi-paradigme): Tesseddu asihel s tɣawsa, asihel amesɣan, d usihel s tedyanin.

3.2. Tiseddast tigejdanin

[ẓreg | ẓreg aɣbalu]

3.2.1. Imuttiyen

[ẓreg | ẓreg aɣbalu]

JavaScript yesɛa kraḍ n wawalen i usenteḍ n yimuttiyen:

var x = 10;      // Amutti aqbur (var)
let y = 20;      // Amutti s telqeyt n usweḍ (let)
const z = 30;    // Amutti ur yettubeddlen (const)

var: Amutti s telqeyt n tesɣent.

let: Amutti s telqeyt n iḥder.

const: Amutti ur yezmiren ad yettubeddel.

3.2.2. Awalen n tinaḍ

[ẓreg | ẓreg aɣbalu]
if, else, for, while, do, switch, case, break, continue,
return, function, class, new, this, typeof, instanceof,
try, catch, finally, throw, async, await, import, export

3.2.3. Isulayen

[ẓreg | ẓreg aɣbalu]

Isulayen n yimuttiyen, n tseɣnin, d n tɣawsiwin ilaq ad bdun s usekkil, s _, neɣ s $. Ur zmiren ad bdun s umḍan.

4. Tawsit n Isefka

[ẓreg | ẓreg aɣbalu]

JavaScript tesɛa sin n wudmawen n tewsit n isefka:

4.1. Tiwsitin tizwaranin

[ẓreg | ẓreg aɣbalu]
Tawsit Amedya Aglam
number 42, 3.14 Amḍan ummid neɣ amḍan s ticcert
string "Azul" Azrar n isekkilen
boolean true, false Ilem neɣ ulac
undefined undefined Amutti ur yettusbedden
null null Ulac s umata
symbol Symbol('id') Azamal asuf (ES6)
bigint 9007199254740991n Amḍan ameqqran aṭas (ES2020)

4.2. Tawsit n tɣawsa

[ẓreg | ẓreg aɣbalu]

Yal ayen ur nelli ara d tiwsit tizwaranen d taɣawsa. Deg-s:

  • Array (Tafelwit): let arr = [1, 2, 3];
  • Object (Taɣawsa): let obj = {isem: "Samir", leɛmer: 25};
  • Function (Tasɣent): function azur() { return "Azul!"; }

4.3. Aselkem n tewsit (typeof)

[ẓreg | ẓreg aɣbalu]
typeof 42;           // "number"
typeof "Azul";       // "string"
typeof true;         // "boolean"
typeof undefined;    // "undefined"
typeof null;         // "object" (tuccḍa deg umezruy)
typeof {};           // "object"
typeof [];           // "object"
typeof function(){}; // "function"

5. Tiseɣnin

[ẓreg | ẓreg aɣbalu]

5.1. Tasɣent talugant

[ẓreg | ẓreg aɣbalu]
function smerni(a, b) {
    return a + b;
}

5.2. Tasɣent s uneccab – ES6

[ẓreg | ẓreg aɣbalu]
const smerni = (a, b) => a + b;

5.3. Tasɣent d taserkemt tamenzut

[ẓreg | ẓreg aɣbalu]

Deg JavaScript, tiseɣnin d tiserkam timenza: zemrent ad ttwafkent d imuttiyen, ad ttwarrzent d tiɣiratin, d ad ttwarnant ar tefelwin.

const tiseɣnin = [
    x => x * 2,
    x => x + 1
];

6. Taɣawsa d Usihel s Tɣawsa

[ẓreg | ẓreg aɣbalu]

6.1. Asenteḍ n tɣawsa

[ẓreg | ẓreg aɣbalu]
const amdan = {
    isem: "Samir",
    leɛmer: 30,
    azur: function() {
        return `Azul, nekk d ${this.isem}`;
    }
};

6.2. Taserkemt (Class) – ES6

[ẓreg | ẓreg aɣbalu]
class Amdan {
    constructor(isem, leɛmer) {
        this.isem = isem;
        this.leɛmer = leɛmer;
    }
    
    azur() {
        return `Azul, nekk d ${this.isem}`;
    }
}

const samir = new Amdan("Samir", 30);

6.3. Tukkest

[ẓreg | ẓreg aɣbalu]
class Anelmad extends Amdan {
    constructor(isem, leɛmer, asɣar) {
        super(isem, leɛmer);
        this.asɣar = asɣar;
    }
    
    azur() {
        return `Azul, nekk d ${this.isem}, anelmad deg ${this.asɣar}`;
    }
}

6.4. Akwbal

[ẓreg | ẓreg aɣbalu]

Seg ES2022, JavaScript yesɛa iɣewwaṛen usligen s #:

class Amiḍan {
    #azal;
    
    constructor(azal) {
        this.#azal = azal;
    }
    
    awi() {
        return this.#azal;
    }
}

7. Timṣuki n usenqed

[ẓreg | ẓreg aɣbalu]

7.1. Tawtilt

[ẓreg | ẓreg aɣbalu]
if (amḍan > 18) {
    console.log("Meqqer");
} else if (amḍan > 12) {
    console.log("Alemmas");
} else {
    console.log("Mecṭuḥ");
}

7.2. Tineddict

[ẓreg | ẓreg aɣbalu]
// Tineddict for
for (let i = 0; i < 10; i++) {
    console.log(i);
}

// Tineddict while
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}

// Tineddict for...of (i tefelwin)
for (const azal of [1, 2, 3]) {
    console.log(azal);
}

// Tineddict for...in (i tɣawsiwin)
for (const tsarutt in {isem: "Samir"}) {
    console.log(tsarutt);
}

8. Asihel Aramtawan

[ẓreg | ẓreg aɣbalu]

8.1. Callbacks

[ẓreg | ẓreg aɣbalu]

Aɣewwaṛ amezwaru n usihel aramtawan:

function awiIsefka(callback) {
    setTimeout(() => {
        callback({isem: "Samir"});
    }, 1000);
}

8.2. Promise (Lweɛd)

[ẓreg | ẓreg aɣbalu]
function awiIsefka() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve({isem: "Samir"});
        }, 1000);
    });
}

awiIsefka()
    .then(isefka => console.log(isefka))
    .catch(tuccḍa => console.error(tuccḍa));

8.3. Async/Await

[ẓreg | ẓreg aɣbalu]

Tarrayt tatrart i usihel aramtawan:

async function awiIsefka() {
    try {
        const tiririt = await fetch('https://api.example.com/data');
        const isefka = await tiririt.json();
        console.log(isefka);
    } catch (tuccḍa) {
        console.error('Tuccḍa:', tuccḍa);
    }
}

JavaScript teqqel d tameslayt n usihel tameqqrant deg umaḍal n tsenselkimt. Seg wasmi i d-tlul deg 1995, tettwasnerni s waṭas, teqqel d tameslayt i yesɛan aṭas n wudmawen: asihel n Web (frontend d backend), asihel n yisnasen izirazen, tigzi taragmawant, d waṭas n yiḥricen-nniḍen.

S tizeɣt n ECMAScript i d-yettuɣalen yal aseggas, JavaScript tettkemmel ad tettwasnerni, ad d-ternu tiwsitin imaynuten, d ad tessifses asihel i yineflayen.

I yneflayen d yimusnawen n tsenselkimt, JavaScript d tameslayt ilaq ad tt-issinen, acku d nettat i d tameslayt n Web, d yiwet seg tmeslayin yettwasqedcen aṭas deg umaḍal.

Ẓer daɣen

[ẓreg | ẓreg aɣbalu]