Introduction
Welcome to Part 2 of the JavaScript for Beginners Series. In this part, we explore Data Types—how JavaScript handles different kinds of information like text, numbers, and logic.
1. Primitive Data Types (الأنواع الأولية)
These are the most basic data types in JavaScript:
- STRING (النصوص)
- Used for textual data. You can use single quotes ('...'), double quotes ("..."), or backticks (`...`).
- Example: const greeting = "Hello, World!";
- Darija: كيستعمل لتخزين النصوص.
- NUMBER (الأرقام)
- Used for all numbers, including integers and decimals (floating-point numbers).
- Example: let userAge = 25; | const price = 19.99;
- Darija: كيستعمل لتخزين جميع أنواع الأرقام، سواء كانت صحيحة أو فيها الفاصلة.
- BOOLEAN (القيم المنطقية)
- Represents a logical entity and can only have two values: true or false. It is the foundation of decision-making in code.
- Example: const isLoggedIn = true; | let hasPermission = false;
- Darija: كيمثل القيم المنطقية و هو أساس اتخاذ القرارات ف الكود و عندو جوج احتمالات فقط: صحيح True ، خطأ False.
- UNDEFINED (غير معرف)
- A variable that has been declared but has not yet been assigned a value.
- Example: let userCity; // Outputs: undefined
- Darija: هو القيمة ديال أي متغير تم الإعلان ديالو ولكن مزال ما تعطاتو حتى شي قيمة.
- NULL (فارغ)
- Represents the intentional absence of any object value. It is a value you, the programmer, explicitly assign to mean "nothing."
- Example: let selectedUser = null;
- Darija: كيمثل الغياب المتعمد لشي قيمة. يعني نتا كبروغرامور كتعطيها لمتغير باش تقول بلي راه "خاوي" عن قصد.
2. The Non-Primitive Type (النوع المركب)
Object
The most complex and important data type. It is a collection of key-value pairs. Almost everything in JavaScript is an object.
- Darija: هو أهم وأشهر نوع مرّكب، كيتستعمل باش تجمع بّزاف ديال البيانات فبلاصة وحدة على شكل "مفتاح-قيمة" (key-value). تقريبًا كلشي فجافاسكريبت هو اوبجيكت.
Code Example:
const person = {
firstName: "Fatima",
age: 30,
isDeveloper: true
};
3. Pro Tip: Checking The Type with typeof
You can use the typeof operator to find out the data type of any variable.
- Darija: باش تعرف شنو نوع البيانات ديال اي متغير تقدر تستعمل typeof.
Code Example:
console.log(typeof "Hello"); // "string"
console.log(typeof 25); // "number"
console.log(typeof true); // "boolean"
console.log(typeof {name: "Ali"}); // "object"
