Course / دورة
JavaScript in the browserJavaScript في المتصفح
The DOM, events, modern syntax, and talking to a server
الـDOM والأحداث والصيغة الحديثة والتحدث إلى خادم
intermediate 23 lessons 6 chapters 16 hours
Before you start / قبل أن تبدأ: Programming basics , HTML
0 / 23 lessons completed / دروس مكتملة
What you will be able to do / ماذا ستستطيع أن تفعل
- Find, change and create elements on a live page تجد العناصر وتغيّرها وتنشئها في صفحة حيّة
- Respond to what a user does, including on elements added later تستجيب لتصرفات المستخدم، حتى على عناصر أُضيفت لاحقًا
- Work with code that finishes later, without callback tangles تتعامل مع كود ينتهي لاحقًا دون تشابك الاستدعاءات
- Fetch data from a server and handle loading and failure honestly تجلب البيانات من خادم وتعالج التحميل والفشل بصدق
1 The DOMالـDOM 5
-
1
What the DOM is / ما هو الـDOM
Your HTML file is text. What JavaScript talks to is a tree the browser built from it — and the difference between those two explains most of what surprises people first.
ملف HTML خاصتك نص. وما تحادثه JavaScript شجرة بناها المتصفح منه — والفرق بينهما يفسّر معظم ما يفاجئ الناس أولًا.
-
2
Selecting elements / اختيار العناصر
Before you can change anything you have to find it. Two methods cover almost everything, and they use the CSS selectors you already know from a whole course of them.
قبل أن تغيّر شيئًا عليك إيجاده. وطريقتان تغطيان كل شيء تقريبًا، وتستخدمان مُحدِّدات CSS التي تعرفها من دورة كاملة عنها.
-
3
Changing what an element says / تغيير ما يقوله العنصر
Two properties write text into an element, and the difference between them is a security decision rather than a style preference.
خاصيتان تكتبان نصًا في عنصر، والفرق بينهما قرار أمني لا تفضيل أسلوبي.
-
4
Changing how an element looks / تغيير مظهر العنصر
You can set styles directly from JavaScript, and you almost never should. Adding and removing a class keeps the design in the stylesheet where it belongs.
تستطيع ضبط التنسيقات مباشرة من JavaScript، ولا ينبغي أن تفعل تقريبًا. فإضافة صنف وإزالته تبقي التصميم في ملف التنسيق حيث ينتمي.
-
5
Creating and removing elements / إنشاء العناصر وإزالتها
Building a list from data is the most common thing a page does. Doing it by creating elements rather than joining strings is what makes it safe.
بناء قائمة من بيانات أشيع ما تفعله صفحة. وفعله بإنشاء عناصر لا بوصل نصوص هو ما يجعله آمنًا.
2 Eventsالأحداث 4
-
6
Events: making the page respond / الأحداث: جعل الصفحة تستجيب
Everything interactive is the same shape: something happens, and a function you wrote runs. One method attaches that function, and understanding that it is not called by you is the whole idea.
وكل تفاعلي هو الشكل نفسه: يحدث شيء فتعمل دالة كتبتها. وطريقة واحدة تربط تلك الدالة، وفهم أنك لست من يستدعيها هو الفكرة كلها.
-
7
The event object / كائن الحدث
The browser hands your function an argument describing what happened: which element, which key, where the pointer was — and one method that stops the browser doing its normal thing.
يسلّم المتصفح دالتك وسيطًا يصف ما حدث: أي عنصر وأي مفتاح وأين كان المؤشر — ودالة واحدة توقف المتصفح عن فعل عادته.
-
8
Bubbling and delegation / الانتشار والتفويض
An event does not stop where it happened — it travels up the tree. That one behaviour lets you attach a single listener instead of two hundred, and it solves the problem lesson 3 warned about.
الحدث لا يتوقف حيث وقع — بل يسافر صاعدًا في الشجرة. وذلك السلوك وحده يتيح لك ربط مستمع واحد بدل مئتين، ويحل المشكلة التي حذّر منها الدرس 3.
-
9
Forms and validation / النماذج والتحقق
Reading a form, checking it, and telling someone what is wrong. The browser does more of this for free than most people use — and none of it is a substitute for checking on the server.
قراءة نموذج وفحصه وإخبار أحدهم بما الخطأ. والمتصفح يفعل من هذا مجانًا أكثر مما يستخدمه معظم الناس — ولا شيء منه بديل عن الفحص في الخادم.
3 Modern syntaxالصيغة الحديثة 5
-
10
Arrow functions / الدوال السهمية
A shorter way to write a function, used constantly in modern code. The syntax has four forms worth recognising, and one behaviour that is not just shorthand.
طريقة أقصر لكتابة دالة، تُستخدم باستمرار في الشيفرة الحديثة. وللصيغة أربعة أشكال تستحق التعرف، وسلوك واحد ليس مجرد اختصار.
-
11
Destructuring / التفكيك
Pulling values out of an object or an array into named variables, in one line. It appears everywhere in modern code, and once you can read it a great deal of other people's code opens up.
سحب القيم من كائن أو مصفوفة إلى متغيّرات مسمّاة في سطر واحد. ويظهر في كل مكان في الشيفرة الحديثة، وما إن تستطيع قراءته حتى ينفتح لك كثير من شيفرة الآخرين.
-
12
Spread and rest / النشر والبقية
Three dots that mean two opposite things depending on where they stand: spreading a collection out, or gathering loose values in. They are also the standard way to copy an array or an object without changing the original.
ثلاث نقاط تعني شيئين متعاكسين بحسب موضعها: نشر مجموعة، أو جمع قيم متفرقة. وهما كذلك الطريقة المعيارية لنسخ مصفوفة أو كائن دون تغيير الأصل.
-
13
Optional chaining and ?? / التسلسل الاختياري و??
Two small operators that between them remove most of the defensive clutter from code that reads data it did not create. One stops a chain safely; the other supplies a default without swallowing zero.
مؤثران صغيران يزيلان بينهما معظم الفوضى الدفاعية من شيفرة تقرأ بيانات لم تنشئها. أحدهما يوقف سلسلة بأمان، والآخر يوفّر قيمة افتراضية دون ابتلاع الصفر.
-
14
Modules: import and export / الوحدات: import وexport
How a project stops being one enormous file. Each file keeps its own names, publishes the few it wants shared, and states plainly which other files it depends on.
كيف يكفّ مشروع عن كونه ملفًا ضخمًا واحدًا. فكل ملف يحتفظ بأسمائه، وينشر القليل الذي يريد مشاركته، ويصرّح بوضوح بالملفات الأخرى التي يعتمد عليها.
4 Code that finishes laterكود ينتهي لاحقًا 5
-
15
Why asynchronous code exists / لماذا وُجدت الشيفرة اللاتزامنية
A page has one thread, and everything competes for it: your code, the clicks, the scrolling, the drawing. Understanding that single queue is what makes promises and async/await make sense rather than feel like ceremony.
للصفحة خيط واحد، وكل شيء يتنافس عليه: شيفرتك والنقرات والتمرير والرسم. وفهم ذلك الطابور الواحد هو ما يجعل الوعود وasync/await منطقية بدل أن تبدو طقسًا.
-
16
Callbacks and timers / ردود النداء والمؤقتات
A function you hand to somebody else to call later. Timers are the simplest place to see one work, and the honest place to see why nesting them stopped being good enough.
دالة تسلّمها لغيرك لينادينها لاحقًا. والمؤقتات أبسط موضع ترى فيه واحدة تعمل، وأصدق موضع ترى فيه لماذا كفّ تعشيشها عن أن يكون كافيًا.
-
17
Promises / الوعود
The receipt the browser hands you when you ask for something that takes time. It is not the value; it is an object that will eventually hold either the value or the reason there is not one.
الإيصال الذي يعطيك إياه المتصفح حين تطلب شيئًا يستغرق وقتًا. وهو ليس القيمة؛ بل كائن سيحمل في النهاية إما القيمة وإما سبب عدم وجودها.
-
18
async and await / async وawait
The same promises, written as though they were ordinary sequential code. Two keywords, no new machinery underneath — and one performance trap that catches everybody exactly once.
الوعود نفسها مكتوبة كأنها شيفرة تتابعية عادية. كلمتان مفتاحيتان بلا آلة جديدة تحتهما — وفخّ أداء واحد يوقع الجميع مرة واحدة بالضبط.
-
19
Handling errors / معالجة الأخطاء
What
trycan and cannot catch, why an emptycatchis worse than no catch at all, and how to fail in a way that tells the user something true.ما يستطيع
tryالتقاطه وما لا يستطيع، ولماذاcatchفارغة أسوأ من لا التقاط أصلًا، وكيف تخفق على نحو يقول للمستخدم شيئًا صحيحًا.
5 Talking to a serverالتحدث إلى خادم 3
-
20
JSON and saving data / JSON وحفظ البيانات
Text that looks like a JavaScript object but is not one. It is how data crosses between a server and a page, and how a page keeps something between visits — and it loses a few things on the way, quietly.
نص يشبه كائن جافاسكربت وليس كذلك. وهو كيف تعبر البيانات بين خادم وصفحة، وكيف تحتفظ صفحة بشيء بين الزيارات — ويفقد أشياء قليلة في الطريق بهدوء.
-
21
fetch: talking to a server / fetch: مخاطبة خادم
Asking another machine for data, and the two awaits it always takes. Also the one thing about
fetchthat everybody gets wrong for the first year: a 404 is not an error.سؤال آلة أخرى عن بيانات، والانتظاران اللذان يتطلبهما دائمًا. وكذلك الشيء الوحيد الذي يخطئ فيه الجميع في
fetchطوال السنة الأولى: أن 404 ليست خطأً. -
22
Loading, empty and error states / حالات التحميل والفراغ والخطأ
Anything that takes time has four outcomes, not one, and a page that only draws the happy path is unfinished. This is the lesson that separates code that works on your machine from code other people can use.
لكل ما يستغرق وقتًا أربع نتائج لا واحدة، والصفحة التي ترسم المسار السعيد وحده غير مكتملة. وهذا الدرس هو الذي يفصل شيفرة تعمل على جهازك عن شيفرة يستطيع غيرك استعمالها.