JavaScript
Bring your pages to life
Variables and functions, arrays and objects, the DOM and events, classes, error handling and asynchronous code.
- 32 lessons
- 7 chapters
- Arabic & English
Your progress
What's inside
Lessons go from the basics to advanced topics. Read them in order, or jump to what you need.
Chapter 1
Getting Started
- 1JavaScript IntroductionJavaScript is the programming language of the web. It makes pages interactive, and with Node.js it also runs outside the browser.
- 2Where to Write JavaScriptJavaScript goes inside a <script> tag or in an external .js file. Learn where to place it and why the defer attribute matters.
- 3JavaScript OutputDisplay results with console.log(), write them into page elements with textContent or innerHTML, or show a quick message with alert().
- 4JavaScript SyntaxLearn the rules for writing JavaScript: statements, semicolons, case sensitivity, identifiers and code blocks.
- 5JavaScript CommentsComments explain your code and are ignored when the program runs. Use // for a single line and /* */ for several lines.
Chapter 2
Variables & Data
- 6JavaScript VariablesVariables are named containers for data. Learn to declare them with let and const, and understand the old var and why we avoid it.
- 7JavaScript Data TypesJavaScript has seven primitive data types plus objects. Get to know them, and use the typeof operator to check the type of any value.
- 8JavaScript OperatorsOperators perform actions on values: arithmetic, assignment, comparison and logical operators, plus the modern ?? and ?. operators.
- 9JavaScript StringsStrings store text. Learn about quotes, template literals, escape characters and the length property.
- 10String MethodsBuilt-in string methods let you search, cut, change case, trim and split text. Here are the ones you'll use every day.
- 11Numbers and MathJavaScript has one number type for both integers and decimals. Learn about decimal precision, toFixed(), converting strings to numbers, NaN and the Math object.
- 12Booleans and ComparisonsA boolean is either true or false. Learn which values are truthy or falsy, and why you should use === instead of ==.
Chapter 3
Control Flow
- 13if...else StatementsUse if, else if and else to run different code depending on conditions, and the ternary operator for short decisions.
- 14The switch StatementThe switch statement compares one value against many possible cases. It's a tidy alternative to long else if chains.
- 15The for LoopThe for loop repeats code a set number of times. It's perfect for counting and for going through arrays.
- 16while and do...while Loopswhile repeats code as long as a condition is true, and do...while always runs at least once. Control any loop with break and continue.
- 17for...of and for...infor...of loops over the values of arrays and strings, while for...in loops over the keys of an object.
Chapter 4
Functions
- 18JavaScript FunctionsFunctions are reusable blocks of code. Learn to declare them, pass parameters, set default values and return results.
- 19Arrow FunctionsArrow functions are a shorter way to write functions with =>. You'll find them everywhere in modern JavaScript, especially with array methods.
- 20Scope and ClosuresScope decides where a variable can be used: block, function or global scope. Closures let functions remember the variables from the scope where they were created.
Chapter 5
Arrays & Objects
- 21JavaScript ArraysArrays store ordered lists of values. Learn to create them, access items by index, and add, remove, find and sort items.
- 22Array Methods: map, filter, reduceWork with arrays like a pro using forEach, map, filter, reduce, find, some and every, with practical examples based on student grades.
- 23JavaScript ObjectsObjects group related data and behavior into key-value pairs. Learn about properties, methods, this, and how to loop over objects.
- 24Destructuring and SpreadDestructuring unpacks values from arrays and objects into variables. The spread operator ... copies and merges values, and the rest syntax collects them.
- 25JavaScript JSONJSON is the standard text format for exchanging data. Convert objects to JSON with JSON.stringify() and back with JSON.parse().
Chapter 6
The Browser
- 26The HTML DOMThe DOM is JavaScript's live model of the page. Learn to select elements, change their text, HTML, styles and classes, and create new elements.
- 27JavaScript EventsEvents let your code react to users. Use addEventListener() for clicks, typing and form submissions, read the event object, and meet event delegation.
- 28Forms and ValidationRead values from form fields, validate them with JavaScript, show helpful error messages, and stop invalid submissions with preventDefault().
Chapter 7
Modern JavaScript
- 29JavaScript ClassesClasses are templates for creating objects. Learn about the constructor, methods, inheritance with extends and super, and getters.
- 30Error HandlingHandle errors gracefully with try, catch and finally, create your own errors with throw, and learn the common error types.
- 31Promises and async/awaitHandle tasks that take time without freezing the page. Learn setTimeout, promises with then and catch, and the cleaner async/await syntax.
- 32The Fetch APIUse fetch() with async/await to load JSON data from a server, check the response, and handle network errors properly.