⚡ IS231 · JavaScript Complete Study Guide · Slides JS-1 & JS-2 · All Exam Questions

JavaScript
الـ JS من الأساسيات للـ AJAX

2
JS Slide Sets
12
Chapters
4
Exam Sources
70+
Exam Questions
01

What is JavaScript?

Definition · History · ECMAScript Versions · What JS Can Do

JavaScript — ببساطة إيه ده؟

JavaScript هي لغة برمجة بتشتغل جوا الـ browser — يعني عند الـ client مش على الـ server. لو الـ HTML هو "العظام"، والـ CSS هو "الملابس"، فالـ JavaScript هو "الحركة والتفاعل"!

🚨 أهم غلطة اللي الكل بيعملها:
JavaScript ليها علاقة بـ Java؟ ❌ لأ!
اتعملت 1995 في Netscape واسمها الأصلي كان "LiveScript" — Java لغة تانية خالص!
💡 JS بتشتغل فين؟
Interpreter مدمج جوا الـ browser بيشغّلها. مش محتاج compilation زي Java أو C++.

Client-side: بتشتغل عند المستخدم بعد ما الـ browser استلم الـ HTML
Server-side: ممكن برضو بـ Node.js
FIRST JS PROGRAM
<html>
<body>
<script>
  // بيكتب على الصفحة مباشرة
  document.write("Hello World!");
  
  // بيكتب في الـ console
  console.log("Hello Dev!");
  
  // Popup
  window.alert("مرحبا يا عالم!");
</script>
</body>
</html>
🚀 ما اللي JS بتعمله؟ — What can JS Do?
🎭 Dynamic HTML

بتعدل في الـ HTML بعد ما الصفحة اتحملت — تضيف/تمسح/تغير elements

🖱️ User Events

بتتفاعل مع الكليك، الـ hover، الـ submit، الـ scroll

✅ Validation

بتتحقق من الـ forms قبل ما يتبعتوا للـ server

🍪 Cookies

بتعمل وتقرأ cookies عشان تحفظ بيانات المستخدم

🔄 AJAX

بتجيب بيانات من الـ server من غير ما تـreload الصفحة!

🔢 Full Language

لغة برمجة كاملة — variables, functions, classes, OOP

📅 ECMAScript History — أهم Version Numbers
VersionYearأهم Features
ES31999Regular Expressions, try/catch
ES52009"use strict", JSON, forEach, map, filter, reduce
ES6 / ES20152015let/const, Arrow functions, Classes, Promises, Modules — الأهم!
ES7–ES142016–2023async/await, flat, findIndex, الكثير
⚡ من الامتحان: The newest version mentioned in slides = ES14 (ECMAScript 2023). Newest standard = ECMAScript 2024 (ES15).
🔄 JS fits where in the Web Cycle?
1
Client sends request
Browser → Server (HTTP)
2
Server responds
HTML + CSS + JS files
3
Browser renders HTML
Displays the page structure
4
JS runs ⚡
JavaScript executes — user interaction begins!
💡 Key Point: JS user interaction doesn't require communication with the server — بيشتغل locally على الـ browser!
02

Adding JavaScript to HTML

Internal · External · Placement · console.log · window.alert

📝 3 طرق لإضافة JavaScript
1️⃣ Internal — في <head>
HTML
<head>
<script>
function greet() {
  alert("Hi!");
}
</script>
</head>

بيتحمل قبل الـ body — مناسب للـ functions

2️⃣ Internal — في <body>
HTML
<body>
<script>
  document.write(
    "Hello!"
  );
</script>
</body>

بيشتغل وهو الـ page بيتحمل

3️⃣ External File ✅
HTML
<script
  src="myscript.js"
></script>

/* في myscript.js: */
/* JS code فقط — بدون HTML! */

الأفضل — ملف منفصل

🚨 مهم جداً للامتحان:
• External JS file → <script src="file.js"></script> مش href ولا link!
• مش <import src="file.js"> ولا <script link="file.js">
• External JS file = مش المفروض يحتوي على HTML tags!
💬 Built-in Interaction Methods
INTERACTION METHODS — من الامتحانات
// Console — للـ developers فقط
console.log("Check this!");    ← final-2024 Q11

// Alert Box — popup للمستخدم
window.alert("Hello!");         ← final-2024 Q12

// Confirm Box — Yes/No
window.confirm("Are you sure?");

// Prompt — input from user
window.prompt("Your name?", "Ahmed");

// Write to HTML page
document.write("Hello World!");
document.writeln("With newline");
⚡ من الامتحانات:
console.log() → بيكتب في الـ browser console
window.alert() → بيعمل popup box

console.write() ❌ — مش موجود!
console.output() ❌ — مش موجود!
window.alertHTML() ❌ — مش موجود!
window.alertBox() ❌ — مش موجود!
💡 innerHTML — بتعمل إيه؟
بتحدد أو بتقرأ محتوى الـ HTML element.

document.getElementById("demo").innerHTML = "New text";

innerHTML vs innerText: innerHTML بيفسر HTML tags، innerText بيعاملها كـ text عادي.
🎯

Quiz — JS Foundations

أسئلة من final-2024 و final-2025

Q1 final-2024 Q3
Which of the following statement(s) is true about JavaScript?
A It is a scripting language used to make the website interactive
B It is an advanced version of Java for Desktop and Mobile application development
C It is a markup language of Java to develop webpages
D All of the above
✅ JavaScript = scripting language للـ interactivity. ليها علاقة بـ Java؟ لأ! JavaScript مش advanced version من Java، واسمها الأصلي كان LiveScript. مش markup language برضو (HTML هي الـ markup).
Q2 final-2024 Q7
Which is the correct syntax to call an external JavaScript file in the current HTML document?
A <script src="jsfile.js"></script>
B <script href="jsfile.js"></script>
C <import src="jsfile.js"></import>
D <script link="jsfile.js"></script>
✅ External JS file = <script src="file.js"></script>. الـ attribute هو src مش href (href للـ links والـ CSS). مفيش <import> tag في HTML. مفيش link attribute في script.
Q3 final-2024 Q11
Which JavaScript method is used to write on browser's console?
A console.write()
B console.log()
C console.output()
D console.writeHTML()
✅ console.log() هي الـ method الوحيدة الصح. console.write() مش موجودة. console.output() مش موجودة. console.writeHTML() مش موجودة.
Q4 final-2024 Q12
Which JavaScript method is used to write into an alert box?
A window.alertHTML()
B window.alert()
C window.alertBox()
D window.alertContent()
✅ window.alert() هو الـ method الصح. ممكن تكتبها بـ alert() فقط بدون window لأن window هو الـ global object. باقي الـ options مش موجودة.
Q5 final-2024 Q9
Which property is used to define the HTML content to an HTML element with a specific id?
A innerText
B innerContent
C elementText
D innerHTML
✅ innerHTML هو الـ property المستخدم لتحديد أو قراءة HTML content. innerText موجود لكنه بيتعامل مع النص فقط مش الـ HTML tags. innerContent وelementText مش موجودين.
Q6 final-2025 Q39
Which of the following is true about JavaScript syntax?
A It is case-insensitive
B Semicolons are mandatory at the end of every statement
C It is case-sensitive
D White spaces are not allowed
✅ JavaScript is case-sensitive! يعني myVar ≠ MyVar ≠ MYVAR. Semicolons مش mandatory — JavaScript بيعملها ASI (Automatic Semicolon Insertion) بس الـ best practice تكتبها. White spaces مسموح بيها.
03

Variables & Data Types

var · let · const · typeof · Type Conversion

📦 var vs let vs const — الفرق الجوهري!
VAR vs LET vs CONST
// var — function-scoped (قديم)
var x = 10;
var x = 20; // OK — ممكن تعيد التعريف
x = 30;    // OK — ممكن تعدّل

// let — block-scoped (ES6 ✅)
let y = 10;
// let y = 20; ❌ لا يمكن إعادة التعريف
y = 20;    // OK — ممكن تعدّل

// const — block-scoped, read-only (ES6 ✅)
const PI = 3.14;
// PI = 3.15; ❌ TypeError — لا يمكن التغيير!
// const PI; ❌ لازم تعطيها قيمة وقت التعريف!
Featurevarletconst
ScopeFunctionBlockBlock
Re-declare✅ نعم❌ لا❌ لا
Re-assign✅ نعم✅ نعم❌ لا
HoistingYes (undefined)Yes (TDZ)Yes (TDZ)
🚨 من final-2024 Q15:
const VALUE = 10; VALUE = 20; → يعطي TypeError لأن const لا يمكن إعادة تعيينه. مش ValueError!
🎯 Scope Visualization — فين بيعيش الـ Variable?
🌍 Global Scope — var x = 10 (accessible everywhere)
var globalVar = "I'm global";
🏠 Function Scope — var is trapped here
function myFunc() { var funcVar = "inside function"; }
🔒 Block Scope — let/const only!
if(true) { let blockVar = "only here!"; const BLOCK_CONST = 42; }
SCOPE EXAM EXAMPLE — final-2024 Q17
var X = 10;       // global variable
function myfunc() {
  let x = 20;   // مختلف! lowercase 'x' وlet
}
document.write(X);  // ⚡ Output: 10

// ليه؟ لأن:
// 1. document.write بيقرأ X الـ global مش x الـ local
// 2. X (uppercase) ≠ x (lowercase) — case-sensitive!
// 3. الـ function مش اتنفذت حتى لو تعرفت
🎨 Data Types & typeof
number
42, 3.14, -7 → typeof(3.14) = "number"
string
"hello", 'world' → typeof("x") = "string"
boolean
true, false → typeof(true) = "boolean"
object
{}, [], null → typeof([]) = "object"
undefined
var a; → typeof(a) = "undefined"
function
function(){} → typeof(fn) = "function"
🚨 typeof الأكثر في الامتحانات:

typeof(12.34)"number" (مش "float" ولا "int"!)
typeof([1,2,3])"object" (arrays هي objects!)
typeof(null)"object" (معروف كـ JavaScript bug!)
typeof(undefined)"undefined"
TYPEOF EXAMPLES
var x = 12.34;
typeof(x);  → "number"

var arr = [1,2,3];
typeof(arr); → "object"

function f() {}
typeof(f);  → "function"

var a;
typeof(a);  → "undefined"
🔄 Type Conversion — أكثر حاجة بتيجي في الامتحانات!

الـ + مع strings بيعمل concatenation. باقي الـ operators بيحوّل الـ string لـ number.

TYPE COERCION — الأمثلة اللي بتيجي في الامتحان
// + مع string = concatenation (من اليسار للليمين)
10 + 20 + "5"  → "305"  ← final-2024 Q18
// ليه؟ 10+20=30 أولاً (numbers), ثم 30+"5"="305"

100 - 20 + "5" → "805"  ← mid-2023 Q44
// ليه؟ 100-20=80 (arithmetic), ثم 80+"5"="805"

"20" + 10       → "2010" ← final-2024 Q60
"20" - 10       → 10    ← الـ - بيحوّل string لـ number!

"37" - 7        → 30    ← numeric subtraction
"37" + 7        → "377" ← string concatenation!
⚡ القاعدة:
لو أي operand string + الـ operator هو + → string concatenation من وقت ما لقى الـ string

لكن لو الـ operator هو - أو * أو / → يحوّل الـ string لـ number!
🚨 Truthy/Falsy Values:
False: null, undefined, 0, "" (empty string), false
True: كل حاجة تانية — حتى "0" وarray فاضي []!
04

Scope & "use strict"

Global Variables · Block Scope · Strict Mode

🔒 "use strict" — وضع الانضباط!
"USE STRICT" EXAMPLES
// بدون strict mode:
x = 10; // Works! (global variable)

// مع strict mode:
"use strict";
x = 10; // ❌ ERROR! x is not declared

// الصح:
"use strict";
let x = 10; // ✅

// ملاحظة: strict mode بيمنع:
// - استخدام variables بدون تعريف
// - حذف variables بـ delete
// - استخدام reserved words كـ variable names
💡 "use strict" بتعمل إيه؟
بتحوّل JS لـ "strict mode" اللي بيمنع الـ bad practices:

• لا يسمح بـ undeclared variables
• بيعطي errors بدل ما يتجاهل الأخطاء
• بيحسّن الـ performance
• بيجهّز الكود لـ future JS versions
🚨 من final-2025 Q40 & Q41:
'use strict' does: Enforces stricter parsing and error-handling rules

In strict mode: x = 10; → Error: x is not defined
(مش بيعطي 10 ولا undefined!)
🌐 Global Variables — Window Object
GLOBAL VARIABLES
var a = 10;  // property of window (var)
b = 20;      // implicit global (no var/let/const)

console.log(window.a); // 10
console.log(window.b); // 20

delete a; // false — var variables can't be deleted
delete b; // true — implicit globals CAN be deleted

console.log(a); // 10 (still exists)
console.log(b); // ReferenceError! (was deleted)

// عدد طرق تعريف الـ variable:
var x = 1;  // 1
let y = 2;  // 2
const z = 3; // 3 ← إجمالي: 3 طرق!
💡 من final-2025 Q48: How many ways are there to declare a variable? → 3 (var, let, const)
🎯

Quiz — Variables & Scope

أسئلة من final-2024 و final-2025

Q1 final-2024 Q14
Which is the correct syntax to declare a constant in JavaScript?
A const constant_name;
B constant_name const;
C constant_name const = value;
D const constant_name = value;
✅ const اسمها = قيمة — الكلمة المحجوزة في الأول. const مش ممكن تُعرَّف بدون قيمة (A خطأ). اسم الـ constant مش ممكن يجي أول (B وC خطأ).
Q2 final-2024 Q15
What will be the output of: const VALUE=10; VALUE=20;
A 10
B 20
C ValueError
D TypeError
✅ TypeError! لأن const بعد تعريفها مش ممكن تتغير قيمتها. الـ error هو TypeError (مش ValueError — ده Python). JavaScript بيرفع TypeError لما تحاول تعيين قيمة لـ const.
Q3 final-2024 Q17
What will be the value of X? var X=10; function myfunc(){ let x=20; } document.write(X);
A 20
B 10
C ValueError
D TypeError
✅ Output = 10. لأن: X (uppercase) هو global variable بقيمة 10. x (lowercase) داخل myfunc هو local variable — JS case-sensitive! الـ function مش اتنفذت. document.write يقرأ X الـ global = 10.
Q4 final-2024 Q18
What is the output of: var a = 10 + 20 + "5";
A 35
B 305
C TypeError
D ValueError
✅ "305"! خطوة خطوة: (10 + 20) = 30 أولاً (كلاهم numbers), ثم (30 + "5") = "305" (string concatenation). لو كان "5" + 10 + 20 كان هيبقى "51020"!
Q5 final-2024 Q19
What will be the output? var x = 12.34; document.getElementById("test").innerHTML = typeof(x);
A int
B float
C long
D number
✅ "number"! JavaScript ليها type واحد للأرقام هو "number" — مفيش int, float, long, double. كل الأرقام (سواء 42 أو 3.14) هم "number".
Q6 final-2024 Q35
What will be the output? var a; document.write(a);
A 01234
B 0
C Error
D None of the previous
✅ None of the previous! var a بدون قيمة = undefined. document.write(undefined) → يكتب "undefined" على الصفحة. لا 0 ولا error ولا 01234.
Q7 final-2025 Q42
What is the difference between var, let, and const?
A var is block-scoped, let and const are function-scoped
B var is function-scoped, let and const are block-scoped
C var and let are block-scoped, const is function-scoped
D All are block-scoped
✅ var = function-scoped (بيبقى موجود في كل الـ function), let وconst = block-scoped (بيبقى موجود جوا {} بس). ده الفرق الجوهري!
Q8 final-2025 Q40
What does 'use strict' do in JavaScript?
A Prevents errors in the code
B Enforces stricter parsing and error-handling rules
C Allows use of old JavaScript syntax
D Removes debugging restrictions
✅ "use strict" بتطبّق قواعد أكثر صرامة في الـ parsing والـ error handling. مش بتمنع الأخطاء (A غلط) ومش بتسمح بـ old syntax (C غلط).
Q9 final-2025 Q41
What is the result of running this code in strict mode? "use strict"; x = 10; console.log(x);
A 10
B Error: x is not defined
C undefined
D NaN
✅ Error! في strict mode، استخدام variable بدون تعريفها (بـ var/let/const) بيطلع ReferenceError. بدون strict mode كانت هتعمل implicit global variable وتطبع 10.
Q10 final-2024 Q16
Can we use a function as a variable value?
A Yes
B No
✅ Yes! Functions في JavaScript هم "first-class citizens" — ممكن تعمل: const f = function() {}; أو const f = () => {}; وبعدين تستخدمها زي أي variable!
05

Functions & Arrow Functions

Declaration · Expression · Default Params · Arrow Syntax

🔧 3 طرق لكتابة Functions
FUNCTION STYLES — الـ 3 طرق
// 1. Function Declaration — التقليدي
function add(a, b) {
  return a + b;
}

// 2. Function Expression — بتخزنها في variable
const add = function(a, b) {
  return a + b;
};

// 3. Arrow Function (ES6) — الأقصر والأجمل!
const add = (a, b) => a + b;
// لو statement واحدة: مش محتاج {} ولا return!

// Default Parameters (ES6)
function greet(name = "Guest") {
  return "Hello " + name;
}
greet();        → "Hello Guest"
greet("Ahmed"); → "Hello Ahmed"
➡️ Arrow Functions — الـ Exam Example!
ARROW FUNCTION — final-2024 Q64
const f = (a, b) => a + b + 5;

f(4, 5)  = 4 + 5 + 5 = 14 ✅
f(3, 4)  = 3 + 4 + 5 = 12

// Arrow syntax مختلفة:
const sq  = x => x * x;    // parameter واحد — بدون ()
const hi  = () => "Hello"; // بدون params
const sum = (a,b) => {      // multi-line: لازم {} وreturn
  let result = a + b;
  return result;
};

// map/filter مع Arrow — من الامتحانات!
myNumbers.map((value) => value * 4);
myNumbers.filter((value) => value < 10);
🚨 من final-2024 Q64:
const f = (a,b) => a+b+5;
f(4,5) = 4+5+5 = 14

مش 9 (4+5) ومش 14 أو أي حاجة تانية!
💡 Map & Filter Syntax — final-2024 Q65 & Q66:

Multiply by 4:
myNumbers.map((value)=>value*4)
myNumbers.map(value*4) ❌ — لازم function!

Filter less than 10:
myNumbers.filter((value)=>value<10)
myNumbers.map(...) ❌ — map مش filter!
06

eval · Rest Parameter · Spread Operator

eval() · ...rest · ...spread · arguments

⚠️ eval() — بيشغّل String كـ JS Code
EVAL — من الامتحانات
// Q30 — final-2024
let x = 10;
let y = 20;
let text = "x * y";
let result = eval(text);
// eval("x * y") = x * y = 10 * 20 = 200
document.getElementById("demo").innerHTML = result;
// Output: 200 ✅

// Q47 — mid-2023
let x = 10, y = 20;
let text = "y-x";
let result = eval(text); = y-x = 20-10 = 10
document.write(result); // Output: 10

// Q78 — final-2025 (الصعبة!)
var writeMe = "console.log('document.writeln(x);')"
var x = 13
eval(writeMe);
// eval runs: console.log('document.writeln(x);')
// → prints the STRING "document.writeln(x);" in console
// NOT x's value! Because x is inside single quotes
⚠️ eval() — Avoid in Production!
Security risk — بيشغّل أي code!
Performance problem — JS engine مش قادر يـoptimize.
🚨 final-2025 Q78 — الفخ!
writeMe = "console.log('document.writeln(x);')"

eval بيشغّل: console.log('document.writeln(x);')

النتيجة: بيكتب الـ string "document.writeln(x);" في الـ console — مش قيمة x!
لأن 'document.writeln(x);' هو نص داخل single quotes.
📦 Rest Parameter (...) — يحوّل Arguments لـ Array
REST PARAMETER — من الامتحانات
// ...args يجمع كل الـ arguments في array
function test(...args) {
  document.write(typeof(args)); → "object"
  // ليه object؟ لأن arrays هم objects!
}
test(12); // args = [12]

// Sum example from slides:
function sum(...args) {
  let total = 0;
  for (let arg of args) total += arg;
  return total;
}
sum(1, 2, 3, 4, 5); → 15

// Multiply example from final-2025:
function multiply(...myNumbers) {
  let total = 1;
  for (let n of myNumbers) total *= n;
  return total;
}
💡 ... يعمل إيه بالظبط؟
الـ ... في الـ function parameters:
Rest Parameter → يجمع arguments في array

typeof(args) = "object"
لأن arrays في JS هم objects!
⚡ من final-2025 Q38:
The "..." will:
→ Allow the function to change the arguments to an array

مش "waiting for more arguments" ولا "distributing to separate numbers".
🎯

Quiz — Functions & eval

أسئلة من final-2024 · mid-2023 · final-2025

Q1 final-2024 Q33 / final-2025 Q68
What will be the output? function test(...args){ document.write(typeof(args)); } test(12);
A NaN
B number
C object
D array
✅ "object"! الـ ...args بيحوّل كل الـ arguments لـ array. الـ array في JavaScript هو object. typeof([12]) = "object". مفيش type اسمه "array" في typeof!
Q2 final-2025 Q38
In the following function: function multiply(...myNumbers){...}, the "..." will:
A Allow the function to be waiting for more arguments
B Allow the function to change the arguments to an array
C Allow the function to distribute the arguments to separate numbers
D None of the answers
✅ الـ ... (Rest Parameter) بيجمع كل الـ arguments في array واحد. function multiply(...myNumbers) → myNumbers بيبقى array من كل الـ arguments.
Q3 final-2024 Q64
const f = (a,b) => a+b+5; — What will f(4,5) return?
A f(4,5) will return 9
B f(3,4) will return 12
C f(4,5) will return 14
D Not a correct syntax for an arrow function
✅ f(4,5) = 4+5+5 = 14 ✓. f(3,4) = 3+4+5 = 12 (مش 12 في الـ option B لأن B بيقول f(3,4) will return 12 وده صح فعلاً، لكن السؤال عن f(4,5) اللي = 14). السؤال بيسأل عن f(4,5)!
Q4 final-2024 Q30
What is the output? let x=10; let y=20; let text="x * y"; let result=eval(text); innerHTML=result;
A x * y
B 200
C valueError
D None of the previous
✅ 200! eval("x * y") بيشغّل الـ string كـ JS code. هيلاقي x=10 وy=20 في الـ scope الحالي. 10 * 20 = 200.
Q5 mid-2023 Q47
What is the output? let x=10; let y=20; let text="y-x"; let result=eval(text); document.write(result);
A y-x
B "10"
C valueError
D None of the previous
✅ None of the previous! الإجابة هي الرقم 10 (y-x = 20-10 = 10). لكن "10" بالـ string في option B مش هي الإجابة الصح — النتيجة هي number 10. 10 مش موجود في الـ options → d.
Q6 final-2025 Q78
var writeMe = "console.log('document.writeln(x);')"; var x = 13; eval(writeMe); — What is the output?
A Prints 13 in the console
B Writes 13 to the body of the document
C Writes "document.writeln(x);" to the body of the document
D Prints "document.writeln(x);" in the console
✅ d! eval بيشغّل: console.log('document.writeln(x);') → بيكتب في الـ console الـ STRING "document.writeln(x);" — لأن الـ string هي داخل single quotes ومش هتتـevaluate. x مش هيتعوّض بـ 13.
Q7 final-2024 Q60
x = "20"; y = 10; document.writeln(x + y, x - y); — What is the output?
A 30, 10
B 30, NAN
C 2010, NAN
D 2010, 10
✅ "2010, 10"! x+"20"+10 = "2010" (string concatenation). x-y = "20"-10 = 10 (الـ - بيحوّل الـ string لـ number فعلاً!). writeln مع args متعددة بيفصل بينهم بمسافة.
07

Arrays & ES5 Array Methods

forEach · map · filter · reduce · find · indexOf · concat · flat

📊 Array Methods Overview — الخريطة الكاملة
Methodبيعمل إيه؟بيرجع إيه؟مثال
forEach(fn)بيلف على كل elementundefinedarr.forEach(v => console.log(v))
map(fn)بيحوّل كل elementArray جديد[1,2,3].map(v=>v*2) → [2,4,6]
filter(fn)بيصفّي العناصرArray جديد[1,2,3].filter(v=>v>1) → [2,3]
reduce(fn, init)بيجمع لـ قيمة واحدةSingle value[1,2,3].reduce((t,v)=>t+v, 0) → 6
find(fn)أول element يطابقElement أو undefined[10,20,30].find(v=>v>10) → 20
some(fn)لو أي element يطابقboolean[1,2,3].some(v=>v>2) → true
every(fn)لو كل elements تطابقboolean[1,2,3].every(v=>v>0) → true
indexOf(v)أول index لـ قيمةnumber (-1 لو مش موجود)[10,20,10].indexOf(10) → 0
lastIndexOf(v)آخر index لـ قيمةnumber (-1 لو مش موجود)[10,20,10].lastIndexOf(10) → 2
concat(arr)يدمج arraysArray جديد[1,2].concat(3,4) → [1,2,3,4]
flat(depth)بيفرد nested arraysArray جديد[[1,2],[3]].flat() → [1,2,3]
pop()يشيل آخر elementالـ element اللي اتشال[1,2,3].pop() → 3
🔗 Pipeline Visualization — map → filter → reduce
Input Array
[1, 2, 3, 4, 5]
filter(v>2)
[3, 4, 5]
.filter()
map(v*v)
[9, 16, 25]
.map()
reduce(sum)
50
.reduce()
📉 reduce() — الأكثر في الامتحانات!
REDUCE — Exam Examples
// reduce(callback, initialValue)
// callback(accumulator, currentValue)

// Q21 final-2024: initial = 2
var numbers = [1,2,3,4];
function myfunc(total, value) { return total + value; }
var sum = numbers.reduce(myfunc, 2);
// Start: total=2 (initial), value=1 → 3
// Next:  total=3, value=2 → 5
// Next:  total=5, value=3 → 8
// End:   total=8, value=4 → 12 ✅

// Q22 final-2024: no initial value, subtraction
var numbers = [170, 50, 25];
function myfunc(total, value) { return total - value; }
var sum = numbers.reduce(myfunc);
// Start: total=170 (first element!), value=50 → 120
// End:   total=120, value=25 → 95 ✅

// Q45 mid-2023: initial = 3
var numbers = [1,2,3,4];
var sum = numbers.reduce(myfunc, 3);
// 3+1+2+3+4 = 13 → None of previous (d)!
🚨 القاعدة الذهبية لـ reduce:
• لو في initial value → تبدأ الـ accumulator بـ الـ initial value
• لو مفيش initial value → الـ accumulator يبدأ بـ أول element والـ loop تبدأ من الـ second
🔎 find() vs filter() vs some()
FIND vs FILTER vs SOME
var numbers = [10, 20, 30];
function myFunction(value) { return value > 10; }

// find() → أول element يطابق فقط
numbers.find(myFunction);   → 20 (not [20,30]!) ← Q28 final-2024

// filter() → كل elements تطابق
numbers.filter(myFunction); → [20, 30] (array!)
typeof(numbers.filter(myFunction)) → "object" ← Q31 final-2024

// some() → يرجع boolean
numbers.some(myFunction);   → true (boolean, not array!)
typeof(numbers.some(myFunction)) → "boolean" ← Q49 mid-2023

// map() مع boolean function (Q46 mid-2023):
[45,4,9,16,25].map(v => v > 18)
→ [true, false, false, false, true] ← مش [45,25]!
🔢 indexOf · lastIndexOf · concat · flat · pop
ARRAY METHODS — More Exam Questions
// indexOf vs lastIndexOf — Q32 final-2024
var numbers = [10, 20, 10, 30];
//              0    1    2    3
var y = numbers.lastIndexOf(10); → 2 (last occurrence)
var z = numbers.indexOf(30);     → 3
document.write(y + z); → 5 ✅

// concat — Q34 final-2024
var quiz = [1, 2, 3];
var result = quiz.concat(6, 7, 8);
document.write(result); → 1,2,3,6,7,8 ✅

// pop() — Q68/Q69 final-2024
var myNumbers = [1, 2, 3];
var x = myNumbers.pop(); → x = 3 (LAST element removed!)
// myNumbers is now [1, 2]

// flat() — Q78 final-2024
const myArr = [1, 2, [3, [4, 5, 6], 7], 8];
const newArr = myArr.flat(); // depth=1 by default
→ [1, 2, 3, [4, 5, 6], 7, 8] → written: 1,2,3,4,5,6,7,8

// flat(2) — Q79 final-2025
const myArr = [1, 2, [3, [4, 5, 6, 7], 8]];
myArr.flat(2); → [1, 2, 3, 4, 5, 6, 7, 8] ✅

// {1:"red"} is NOT an array! Q67 final-2024
var colors = {1:"red", 2:"green"}; ← Object, not Array!
// Array uses []. Object uses {}.
🎯

Quiz — Arrays & Methods

أكتر جزء في الامتحانات — تمرن عليه كويس!

Q1 final-2024 Q24
const arr=[10,20,30]; let result=0; arr.forEach(myFunction); function myFunction(value){result+=value;} document.write("Result: "+result);
A Result: 102030
B Result: 60
C Result: 10,20,30
D ValueError
✅ Result: 60! forEach بيلف على كل element ويضيفه لـ result: 0+10=10, 10+20=30, 30+30=60. الـ result خارج الـ function عشان function بتشوفه (closure).
Q2 final-2024 Q25
const values=[10,20,30]; const result=values.map(myFunction); function myFunction(value){return value*value;} document.write("Result: "+result);
A Result: 10,20,30
B Result: 10*10, 20*20, 30*30
C Result: 100,400,900
D Result: 100400900
✅ Result: 100,400,900! map بيعمل array جديد: 10²=100, 20²=400, 30²=900. لما تكتب array بـ write بيعمله toString بيفصل بـ comma. مش 100400900 لأن مفيش + بين الأرقام.
Q3 final-2024 Q21
var numbers=[1,2,3,4]; function myfunc(total,value){return total+value;} var sum=numbers.reduce(myfunc, 2);
A 10
B 12
C 9
D None of the previous
✅ 12! Initial value = 2. 2+1=3, 3+2=5, 5+3=8, 8+4=12. لو مفيش initial كان: 1+2+3+4=10.
Q4 final-2024 Q22
var numbers=[170,50,25]; function myfunc(total,value){return total-value;} var sum=numbers.reduce(myfunc); document.write(sum);
A 100
B 95
C 245
D None of the previous
✅ 95! بدون initial value: total يبدأ بـ 170 (first element). 170-50=120, 120-25=95.
Q5 mid-2023 Q45
var numbers=[1,2,3,4]; function myfunc(total,value){return total+value;} var sum=numbers.reduce(myfunc, 3);
A 10
B 7
C 9
D None of the previous
✅ None of the previous! Initial=3: 3+1+2+3+4=13. 13 مش موجود في الـ options!
Q6 final-2024 Q28
var x=[10,20,30]; function myFunction(value){return value>10;} var y=x.find(myFunction); document.write(y);
A 20,30
B [20,30]
C 20
D None of the previous
✅ 20! find() بترجع أول element فقط يطابق الشرط. 10>10 = false, 20>10 = true → يرجع 20 ويوقف. مش [20,30] — ده filter مش find!
Q7 final-2024 Q31
var numbers=[10,20,30]; function myFunction(value){return value>10;} var y=numbers.filter(myFunction); document.write(typeof(y));
A array
B number
C object
D None of the previous
✅ "object"! filter بترجع array (=[20,30]). typeof(array) = "object" في JavaScript. مفيش type اسمه "array" في typeof!
Q8 mid-2023 Q49
var numbers=[10,20,30]; function myFunction(value){return value>10;} var y=numbers.some(myFunction); document.write(typeof(y));
A array
B number
C object
D None of the previous
✅ None of the previous! some() بترجع boolean (true/false). typeof(true) = "boolean". مش موجودة في الـ options!
Q9 final-2024 Q32
var numbers=[10,20,10,30]; var y=numbers.lastIndexOf(10); var z=numbers.indexOf(30); document.write(y+z);
A 23
B 3
C 5
D None of the previous
✅ 5! [10,20,10,30] → indices: 0,1,2,3. lastIndexOf(10) = 2 (آخر 10 عند index 2). indexOf(30) = 3. 2+3 = 5!
Q10 final-2024 Q34 / mid-2023 Q42
var quiz=[1,2,3]; var result=quiz.concat(6,7,8); document.write(result);
A 1,2,3,6,7,8
B [1,2,3,6,7,8]
C 1,2,3
D None of the previous
✅ 1,2,3,6,7,8! concat بيدمج الأرقام في array جديد. document.write على array بيعمل toString بيفصل بـ comma بدون brackets.
Q11 final-2024 Q69
myNumbers=[1,2,3]; x=myNumbers.pop() — The removed item will be 3?
A True
B False
✅ True! pop() بيشيل ويرجع آخر element. آخر element في [1,2,3] هو 3. ∴ x=3 وصح.
Q12 final-2024 Q67
var colors = {1:"red", 2:"green", 3:"blue"} — Is this one of the ways of defining an array in JavaScript?
A True
B False
✅ False! {} هو Object (dictionary-like) مش Array. Array بيستخدم []. المثال ده = JavaScript Object بـ numeric keys. Array الصح: var colors = ["red","green","blue"];
Q13 final-2025 Q79
const myArr=[1,2,[3,[4,5,6,7],8]]; const newArr=myArr.flat(2); — What is the output?
A 1, 2, 3, [4, 5, 6], 7, 8
B 1, 2, [3, 4, 5, 6], 7, 8
C 1, 2, 3, 4, 5, 6, 7, 8
D None of the previous
✅ 1,2,3,4,5,6,7,8! flat(2) بيفرد مستويين: Level 1: [1,2,3,[4,5,6,7],8]. Level 2: [1,2,3,4,5,6,7,8]. كل الـ nesting اتشالت!
Q14 mid-2023 Q55
var h = [45,4,9,16,25].filter((value)=>value<16); document.writeln("h: " + h + "<br>");
A "h: " + 4 + 9 + "<br>"
B h: 4,9
C h: 13
D h: 13<br>
✅ h: 4,9! filter يخد 4 و9 فقط (كلاهم أقل من 16). الـ array [4,9] + "h: " يطبع "h: 4,9". <br> بيتعامل كـ HTML tag فيظهر كـ line break مش كـ text.
08

Objects & Operators

Object Literals · Property Access · delete · typeof · in

🏗️ Object Literals — تعريف الـ Objects
OBJECTS — Definition & Access
// Object literal
var car = {
  color: "red",
  weight: 2000,
  mfr: "Hyundai"
};

// 3 طرق للوصول للـ properties:
car.color;         → "red" ✅ dot notation
car["color"];     → "red" ✅ bracket + string
var p = "color";
car[p];           → "red" ✅ bracket + variable
car[color];       → ❌ ERROR! color not defined

// Properties are called... "Properties"!
// (Q52 mid-2023) Name وTelephonenumber = Properties

// delete operator:
delete car.color;
car.color; → undefined (not deleted from JS, just undefined)

// in operator:
"weight" in car; → true
"color" in car;  → false (was deleted)
⚡ من final-2024 Q29:
const cars = { company:"Honda", color:"white" };
var x = "color";
delete cars.company;
document.write(cars.company); → "undefined"
document.write(cars[x]); → "white"
Combined: "undefinedwhite"
💡 Object properties في الـ JSON format:
JSON.stringify(obj) → Object to String
JSON.parse(str) → String to Object

stringify = to send to server
parse = to use received data
09

ES6 Classes & OOP

class · constructor · extends · super · prototype · Getters

🏛️ ES6 Classes — OOP في JavaScript
CLASS — Definition & Instantiation
// Class Definition
class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
  
  // Getter - final-2025 Q44
  get carName() {
    return this.name;
  }
}
let myCar1 = new Car("Ford", 2014);

// Inheritance (extends & super)
class Model extends Car {
  constructor(name, year, model) {
    super(name, year); // ⚡ Calls parent's constructor!
    this.model = model;
  }
}
// Constructor: function to initialize properties
// super(): calls the parent constructor
🧬 Prototypes & instanceof
PROTOTYPES & INSTANCEOF
// Constructor function (ES5 OOP)
function Cell(r, c) {
  this.row = r;
  this.col = c;
}

// Adding property using prototype
Cell.prototype.width = 20;

var c1 = new Cell(0, 0);
document.write(c1.width); → 20

// instanceof checks if object is of a specific class
if (c1 instanceof Cell) {
  // true!
}
💡 Prototypes:
بتسمحلك تضيف properties و methods لـ Object Constructors اللي موجودة قبل كدة.
Cell.prototype.width = 20; بيخلي كل الـ objects من نوع Cell يمتلكوا width!
⚡ instanceof:
بيختبر إذا كان الـ object اتعمل من constructor معين.
c1 instanceof Cell ➜ true
🎯

Quiz — Objects & Classes

أسئلة الامتحانات (final-2024 & final-2025)

Q1 final-2024 Q20
Which is the correct syntax to access an object property in JavaScript?
A objectName:propertyName
B objectName[propertyName]
C objectName["propertyName"]
D None of the previous
✅ objectName["propertyName"]! دي طريقة الـ bracket notation اللي بنقول فيها اسم الـ property كـ string. الـ option b صح لو كانت المتغير بدون تنصيص بس كقاعدة عامة للـ syntax المباشر بنحتاج النص.
Q2 final-2025 Q43
What is the purpose of the prototype property in JavaScript objects?
A To create new properties in an object
B To define methods and properties for inheritance
C To store the type of the object
D To delete existing properties
✅ To define methods and properties for inheritance! الـ prototype هو أساس الوراثة في الـ JS، وهو بيسمح إن كل الـ objects المتكاريته تورث الخصائص دي.
Q3 final-2025 Q44
In JavaScript, which of the following is a valid getter in an object?
A get name() { return this._name; }
B getter name() { return this._name; }
C get: function() { return this.name; }
D name.get { return this._name; }
✅ get name() {...}. بنستخدم الـ keyword اللى اسمها "get" قبل اسم الـ function مباشرة جوه الـ class أو الـ object.
Q4 final-2025 Q46
In JavaScript, What is the purpose of the constructor method in a class?
A To define static properties of a class
B To initialize object properties
C To inherit methods from another class
D To execute a class directly
✅ To initialize object properties! الـ constructor فائدته الأولى اعطاء القيم الأولية للـ variables ساعة ما نعمل object من الـ class ده (باستخدام كلمة new).
Q5 final-2025 Q47
In JavaScript, What does the super keyword do?
A Creates a new object in the class
B Defines a static method
C Calls the parent class's constructor
D Overrides the parent class methods
✅ Calls the parent class's constructor! لما بنيجي نورث (extends) ونيجي نكتب جوا المتغيرات، لازم أول حاجة ننده على الـ super() عشان نشغل constructor الـ parent.
Q6 final-2025 Q45
What will the following JavaScript code log? const obj={a:1, b:2}; delete obj.a; console.log(obj);
A { b: 2 }
B { a: null, b: 2 }
C { a: undefined, b: 2 }
D Error
✅ { b: 2 }! كلمة delete بتمسح الـ property دي نهائياً من الـ object.. علشان كده بيتبقى `b: 2` بس.
Q7 final-2025 Q48
How many ways are there with which we can declare a variable in javascript?
A Only one
B Three
C Infinitely many
D None of the above
✅ Three! نقدر نعلن عنهم بثلاث كلمات رئيسية وهم: var و let و const.
10

DOM Manipulation

document · Elements · NodeList · Navigation

🌳 The HTML DOM Tree

الـ Document Object Model (DOM) هو هيكل تفريعي أو شجرة بيوصف فيها الـ HTML كـ objects (أو Nodes). ده بيتيح للـ JS إنه يتفاعل مع الـ HTML بسهولة.

Document ├─ <html> (Root element) │ ├─ <head> │ └─ <body> │ ├─ <h2> id="id1" │ │ └─ "Welcome" (Text Node) │ └─ <p>
💡 Nodes Types:
Element Node: زي <p> و <h1>. (nodeType = 1)
Text Node: النص نفسه. (nodeType = 3)
Document Node: الـ document كله.
Attribute: الخصائص للـ elements.

element.firstChild.nodeValue بيجيب النص اللي جوه أي عنصر.
⚡ read-only properties:
في الـ HTML DOM، الـ nodeName والـ nodeType هما خصائص read-only، مقدرش أغيرهم! (امتحان 2024 Q13)
🔎 Finding HTML Elements
FINDING ELEMENTS
// 1. By ID (بيرجع Single Element)
document.getElementById("demo");

// 2. By Tag Name (بيرجع Collection of elements)
var p_list = document.getElementsByTagName("p");
var count = p_list.length; // عدد البرجرافات

// 3. By Class Name
document.getElementsByClassName("center");

// 4. By CSS Selectors
// querySelector: بيرجع أول عنصر بس!
// querySelectorAll: بيرجع NodeList (لكل العناصر اللي بتطابق)
var nodes = document.querySelectorAll("div > p"); ← Q49 final-2025
🚶‍♂️ Navigating the DOM Tree / DOM Collection vs HTMLCollection
CHILDREN & NODES
// childNodes بترجع كل الـ nodes (text و comments والمسافات!)
var n = myElement.childNodes;

// children بترجع الـ Element nodes بس!
var x = document.body.children; // Collection of elements
var y = x[0].children;        // Element nodes only
var z = y[0].firstChild.nodeValue; // النص اللي جواه

// Removing element:
element.remove(); // Q52 final-2025

// Browser Window/History
window.location.href; // بيدينا الـ URL بتاع الصفحة الحالية
window.history.back(); // بيرجعنا للصفحة اللي كانت قبلها في الـ history
🚨 Exam Highlights (final-2025 Q59-Q61):
children: بيرجع Collection of elements.
childNodes: بيرجع Elements, texts, comments.
لو العناصر كانت <li><p>List 1</p></li>:
firstLi.children → Element nodes only (اللي هو <p>)!
P.firstChild.nodeValue → بيطلع النص "List 1".
🎯

Quiz — DOM Manipulation

كل أسئلة الامتحانات المرتبطة بـ DOM

Q1 final-2024 Q8
Which JavaScript method is used to access an HTML element by id?
A getElementById()
B getElement(id)
C getElementById(id)
D elementById(id)
✅ getElementById()! الـ function دي بتيجيب العنصر بالـ id بتاعه. في الاختيار c كاتب الـ variables جوة الأقواس بس كصحة عامة الميثود نفسها اسمها اللي في A.
Q2 final-2025 Q49
What does document.querySelectorAll() return?
A An array of elements
B A single element
C A NodeList
D Undefined
✅ A NodeList! الـ querySelectorAll دايماً بترجع array-like structure بنسميه NodeList.
Q3 final-2025 Q52
How do you remove an element from the DOM?
A element.delete();
B element.destroy();
C element.remove();
D element.clear();
✅ element.remove(); دي الـ method الصح اللي بنستخدمها عشان نمسح الـ element من الـ document خالص.
Q4 final-2024 Q79
To get the value of the text node of the h2 element node, you can use document.getElementById("id1").innerHTML which is equivalent to:
A document.getElementById("id1").text;
B document.getElementById("id1").firstChild.nodeValue;
C document.getElementById("id1").nodeValue;
D none of the above
✅ .firstChild.nodeValue! الـ nodeValue للـ tag نفسه (زي الـ h2) بيكون null! فلازم تروح للـ child الأول (اللي هو الـ Text node) وتجيب الـ nodeValue بتاعها.
Q5 final-2024 Q13
In HTML DOM, which of the following properties are read-only?
A nodeName
B nodeValue
C nodeName and nodeValue
D None of the previous
✅ nodeName! مقدرش أغير اسم الـ tag وأخليه من h1 لـ p! إنما text زي nodeValue عادي نعدل قيمته ونكتب كلام جديد.
Q6 final-2024 Q84
Using document.getElementById("id1").nodeType will return
A 1
B 3
C Element node
D Text node
✅ 1! الـ nodeType بترجع Integer / Number. للـ Tags والـ Elements بترجع دائما رقم 1.
Q7 final-2025 Q58
Based on HTML:

Wel.come

p1

p2

p3

p4

p5

p6

. If we wrote "var x=document.getElementsByTagName('p')" inside a script tag, then the length of x will be:
A 5
B 6
C 4
D None of the previous
✅ None of the previous! الحسبة الصح: برجراف واحد بره، 4 برجرافات جوا الـ div (في واحد استخبى جوا سيكشن)، واتنين بره في الأخر. الإجمالي 7! يعني لا 5 ولا 4 ولا 6!
Q8 final-2025 Q53
What will be the output of "document.getElementById('id1').firstChild.nodeName;"? (where id1 is

Welcome to my page

)
A 1
B 2
C #text
D None of the previous
✅ #text! الـ firstChild هيكون هنا النص (Welcome to my page).. الـ nodeName الخاص بالنصوص مجرد String هو #text دائما.
Q9 final-2025 Q60
If we wrote this code, "y=x[0].children" then y will contain:
A Element nodes only
B Element nodes and text nodes
C null
D None of the previous
✅ Element nodes only! الـ property اللي اسمها children بتجيب العناصر الفعلية (Tags) ومش بتعتبر النصوص مجرد نودز للرجوع. (على عكس childNodes)
Q10 final-2025 Q50
What does window.location.href return?
A The browser's name
B The URL of the current page
C The history of visited pages
D The cookies of the website
✅ The URL of the current page! هترجع الرابط اللي إنت فاتحه حالياً في المتصفح بالكامل.
Q11 final-2025 Q51
What is the purpose of window.history.back()?
A To reload the current page
B To navigate to the previous page in history
C To clear the browser's history
D None of the above
✅ To navigate to the previous page! بتوازي ضغطك على زر الـ Back في المتصفح بتاعك.
11

JSON, Promises, Async

JSON.parse · JSON.stringify · Promise · async / await

📝 JSON — JavaScript Object Notation
Methodبتعمل إيه؟امتى نستخدمها؟
JSON.stringify(obj)Object ➔ Stringتحول الأوبجكت بتاعنا لنص عشان نرفعه للموقع (السيرفر).
JSON.parse(str)String ➔ Objectتترجم البيانات اللي راجعة من الموقع عشان نعرف نقرأها.
💡 سؤال final-2024 Q26:
"Which function is used to serialize an object into a JSON string in JavaScript?"
الإجابة: stringify()
Promises & Async/Await

بما إن لغة الـ JS سريعة ومش بتسحب حاجات بطيئة تعطلها، عشان ننفذ حاجات بتطول زي جلب معلومات من الإنترنت، بنلجأ استخدام وعود الـ Promise.

Pending
In progress...
Fulfilled / Resolved
.then()
Rejected
.catch()
ASYNC & AWAIT (final-2025 Q80)
async function f() {
  let promise = new Promise((resolve, reject) => {
    setTimeout(() => resolve('done!'), 1000);
  });
  
  // الكلمة دي هتجبر الكود إنه يوقف انتظار للوعد ده أنه يتحقق!
  let result = await promise; 
  console.log(result); // Output: done! (بعد مرور 1 ثانية)
}
f();
12

AJAX & Fetch API

XMLHttpRequest · Fetch · Asynchronous Server Calls

🔄 AJAX Definition

كلمة AJAX اختصارا لـ Asynchronous JavaScript And XML. ودي الطريقة اللي بندمج بيها اتصالنا بقاعدة البيانات من غير ما نضطر إننا نعمل Reload أو نحدث الـ Page (تحديث جزء بيتم بس!) (امتحان 2025 Q31)

OLD WAY: XMLHttpRequest
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    // 4 يعني الطلب خلص وكل حاجة تمام!
    // 200 يعني الـ Status طالعة Successful
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  // true معناها ان الطلب Asynchronous (بيتم في الخلفية)
  xhttp.open("GET", "data.txt", true);
  xhttp.send();
}
NEW WAY: Fetch API
// تقنية Fetch أحدث وأسهل بكتير لأنها بتعتمد على استخدام الـ Promises!
fetch("data.txt")
  .then(response => response.text())
  .then(text_data => {
    document.getElementById("demo").innerHTML = text_data;
  });
🎯

Quiz — Modern JS & AJAX

Q1 final-2024 Q26
Which function is used to serialize an object into a JSON string in JavaScript?
A parse()
B convert()
C stringify()
D None of the previous
✅ stringify()! عشان نجهز الأوبجكت بتاعنا ونبعته للإنترنت لازم نحوله لشكل JSON وده اللي بتعمله بالظبط stringify.
Q2 final-2025 Q31 (TF)
AJAX is used for refreshing the page content by sending a request to the server and updating the whole HTML page from the response.
A False
B True
✅ False! الـ AJAX اتخلق أساسا عشان ميحدثلكش الصفحة كلها بتاعت الـ (HTML page) ويعملك تعديل في جزئية صغيرة معينة من غير ما يضطر يعمل reload شامل للصفحة.
Q3 final-2025 Q80
async function f() { let promise = new Promise((resolve) => setTimeout(()=>resolve('done!'), 1000)); let result = await promise; console.log(result); } f();
A first!
B done!
C JavaScript error
D Something else
✅ done! طالما إننا كاتبين await، الكود هيستنى ثانية لحد ما الـ promise تخلص بنجاح وهتخزن النتيجة في متغير اسمه result وهتم طباعته على طول وهو done!
📋

Exam Cheat Sheet

Quick Reference for Final Revision

⚡ Type Coercion rules

+ with string
Concatenates left-to-right
"20"+10 ➔ "2010"
10+20+"5" ➔ "305"
-, *, / with string
Converts to number
"37"-7 ➔ 30
"10" * 2 ➔ 20
eval("str")
Executes string as JS. eval("x*y") uses current x and y.

🚀 Important typeofs

typeof(12.34)
"number" (no float/int)
typeof([1,2,3])
"object"
typeof(null)
"object"
typeof(undefined variable)
"undefined"

🔥 Scope & strict

var / let / const
var = function scope
let/const = block scope
const VALUE = 10; VALUE = 20;
TypeError (re-assignment not allowed)
"use strict"
Stricter parsing. x = 10; without let/var triggers ReferenceError.

🔍 Array Methods Returns

map(), filter()
Returns NEW Array
some(), every()
Returns Boolean
find()
Returns first matching Element / Value
reduce(func, init)
Without init: starts at index 1.
With init: starts at init.