FacebookTwitterLinkedIn

English translation by ChatGPT

Ahmed Zayed 1/2/1/1 أساسيات الجافاسكريبت'المتغيرات'Ahmed Zayed 1/2/1/1 أساسيات الجافاسكريبت'المتغيرات'

Course

دورة تدريبية

1/2/1/1 أساسيات الجافاسكريبت'المتغيرات'

تطوير المواقع الإلكترونية MEAN-Stack from A to Z التأسيس Level1

تقريبا تتشارك جميع لغات البرمجة الحديثة بنفس المكونات أو الأساسيات و غالبا ما تكون متشابهة في طريقة الكتابة أيضا عموما لن تخلوا لغة برمجة من:

الـ Data types أنواع البيانات

تنقسم أنواع البيانات في الـ JS إلي أنواع بيانات أساسية أو أولية أو مدمجة تبعا لترجمتك لكلمة primitive و هي أنواع البيانات المحددة الواضحة مثل أن تكون نوع البيانات رقمية أو نصوص و هكذا أنواع بيانات non – primitive و هي بيانات يمكن أن يطلق عليها هجينة بشكل مجازي فقد تكون خليط من انواع البيانات و عموما في هذه المحاضرة سنتطرق إلي الـ primitive data types بينما في المحضرة القادمة سنتطرق للـ non – primitive data types في المحاضرة القادمة.

أنواع الـ primitive types :

  1. رقم Number
  2. رقم كبير BigInt
  3. نصوص String
  4. منطقية Boolean
  5. غير معرف Undefined
  6. فارغ أو غير موجود Null
  7. رمز Symbol

الـ variables المتغيرات

المتغيرات ببساطة هى و بشكل مجازي وعاء نقوم بإنشاءه ليحتوى على بيانات و نعطيه إسما لنكون قادرين على استخدامه فيما بعد.

هناك 3 أنواع من المتغيرات أو من طرق تعريف المتغيرات declaration (ترجمتها الحرفية تصريح أو إعلان و لكني أري أن الترجمة المناسبة تعريف حيث تكون وظيفة الـ declaration هو حجز مساحة في الرامات بإسم معين يمكن إستخدامها في تسجيل البيانات بداخلها و استخدامها في الكود ) المتغيرات ترتبط بحدوث فعلين أولا الـ declaration كما ذكرت ثانيا هو الـ assignment أي تخصيص البيانات. أنواع المتغيرات
const var let
و هو اختصار لكلمة constant و هو اختصار لكلمة variable جاءت التسمية من كلمة let بالإنجليزية
يجب ان يقترن تعريف ذلك المتغير بتعيين البيانات الخاصة به
 const x = 0;

لا يمكن تعريفه بدون تعيين البيانات
 const x; 
يمكن تعريفه و تعيين البيانات الخاصة به في خطوتين منفصلتين
1- var x;
2- x = 10;
أيضا يمكن تعريفه و تعيين بياناته في خطوة واحدة var x = 10;
يمكن تعريفه و تعيين البيانات الخاصة به في خطوتين منفصلتين
1-let x;
2-x = 10;
أيضا يمكن تعريفه و تعيين بياناته في خطوة واحدة
let x = 10;
لا يمكن إعادة تعريفه أو إعادة تعيين بياناته يمكن إعادة تعريفه أو إعادة تعيين البيانات لا يمكن إعادة تعريفه و لكن يمكن إعادة تعيين البيانات

هناك أيضا فرق أخر بين الـ var و الـ let و لكن سنتطرق له لاحقا.

يجب مراعاة عند تسمية المتغيرات أن أسمائها تقبل الحروف (بحالتيها الكبيرة و الصغيرة) و تقبل أيضا علامة $ و علامة _ و لا تقبل أي علامات أخرى و تقبل استخدام الأرقام على ألا يبدأ اسم المتغير برقم.

نظرة أعمق على المتغيرات و أنواع البيانات:

تعتبر لغة الـ JS غير محددة نوع البيانات not data typed يمكن للمتغيرات أن تحمل أنواع مختلفة من أنواع البيانات مثلا:
Code

      var x = "hi";
      x = 0;
     console.log(x);
      //output : 0
  
في المثال السابق تم إنشاء متغيير و تعيين له بيانات من نوع string و بعدها تم إعادة تعيين المتغير بنوع أخر من البيانات من نوع number و تستطيع JS تحديد نوع المتغير بما يحمله من بيانات في اللحظة الحالية و إجراء العمليات الخاصة بها فمثلا البيانات الرقمية number يمكن إجراء العمليات الحسابية عليها مثل:
Code

  var x = 5;
  console.log(x + 1);
  //output: 6
- ماذا لو حاولنا جمع متغير نصي string , في هذه الحالة سيتم لصق النصين معا فيما يسمي concatenation و هي عملية دمج تحدث بين نصين مثل
Code

      var x =" my name is ";
      console.log(x + 'ahmed');
      //output:  my name is ahmed
- ماذا لو حاولنا جمع رقم بنص , في هذه الحالة لن تعتبر JS أن علامة + هي علامة للجمع و لكن ستعتبها علامة لدمج بين نصين مثل
Code

      var x = 10;
      console.log(x + 'ahmed');
      //output: 10ahmed
- كيف يمكن تغيير قيمة المتغير نفسه بعملية حسابية أو منطقية مثلا كيف أستطيع أن أزيد رقم 5 علي قمية متغير قيمته 10 لتصبح قيمة المتغير 15 , يمكن القيام بتلك العملية كالتالي:
Code

      var x = 10;
      x = x + 5
      console.log(x);
      //output: 15
ايضا يمكن زيادة المتغير الرقمي بـ1 عن طريق x++ أو ++X كالتالي:
Code

var x = 10;
x++;
console.log(x);
//output: 11
أو
Code

      var x = 10;
      ++x;
      console.log(x);
      //output:11
لكن هناك فرق بين x++ و ++X عندما يتم كتابة المتغير اولا يتم اعادة تعيين المتغير بقيمته الحالية و بعد ذلك زيادة عليها 1 اما لو كتبنا ++ اولا و بعد ذلك اسم المتغير فسيتم زيادة قيمة المتغير أولا و من بعد إعادة تعيينه فمثلا
Code

      var x = 10;
      console.log(x++);
في هذا المثال سيكون النتيجة المكتوبة في الكونسول 10 لان الكود قام بطباعة قيمة المتغير في الكونسل اولا و بعد ذلك قام بزيادة 1 عليها في الذاكرة بينما في هذا الكود
Code

      var x = 10;
      console.log(++x);
في هذا المثال الناتج سيكون 11 لان الكود قام بزيادة المتغير واحد و بعد ذلك قام بطباعته

ايضا يمكن استخدام x-- و --x لإنقاص 1 من المتغير

- يمكن معرفة نوع البيانات التي يحتفظ بها المتغير عن طريق typeof مثل
Code

      var x = 10;
      console.log(typeof x);
      //output: number
و
Code

      var x = true;
      console.log(typeof x);
      //output: boolean
بينما
Code

      var x = 'true';
      console.log(typeof x);
      //output: string
- ايضا يمكن تغيير نوع الداتا في المتغير مثال عرفنا ان x = 10 هو متغير رقمي بينما x = ‘10’ هو متغير نصي و لكنه قابل للتحويل لمتغير رقمي فكيف يمكن تغييره من نصي لرقمي؟ عن طريق parseInt
Code

      var x = '10';
      x =  parseInt(x);
      console.log(typeof x);
      //output: number

1/1/2/1 JavaScript fundamentals 'Variables'

Web Development MEAN-Stack from A to Z Level1 Fundamentals

Almost all modern programming languages share the same components or basics, and they are often similar in the way they are written. Generally, no programming language is without:

Data Types

Data types in JS are divided into primitive or built-in types, depending on your translation of the word "primitive," which are specific and clear data types, such as numeric or text data, and so on. Non-primitive data types are hybrid data types, which can be a mix of different data types. In this lecture, we will focus on primitive data types, while in the next lecture, we will discuss non-primitive data types.

Primitive Types:

  1. Number
  2. BigInt
  3. String
  4. Boolean
  5. Undefined
  6. Null
  7. Symbol

Variables

Variables, simply put, are containers that we create to hold data, and we give them names so that we can use them later.

There are 3 types of variables or ways to declare variables (the literal translation is "declaration," but I believe the appropriate translation is "definition," as the function of declaration is to reserve space in memory with a specific name that can be used to store data and use it in the code). Variables are associated with two actions: first, declaration, as mentioned, and second, assignment, which is assigning data. Types of Variables
const var let
It is short for the word "constant" It is short for the word "variable" The name comes from the English word "let"
The definition of this variable must be accompanied by the assignment of its data
 const x = 0;

It cannot be defined without assigning data
 const x; 
It can be defined and its data assigned in two separate steps
1- var x;
2- x = 10;
It can also be defined and its data assigned in one step var x = 10;
It can be defined and its data assigned in two separate steps
1-let x;
2-x = 10;
It can also be defined and its data assigned in one step
let x = 10;
It cannot be redefined or reassigned It can be redefined or reassigned It cannot be redefined, but its data can be reassigned

There is also another difference between var and let, but we will discuss it later.

When naming variables, it is important to note that their names can include letters (both uppercase and lowercase), the $ symbol, and the _ symbol, but they cannot include any other symbols. They can also include numbers, but the variable name cannot start with a number.

A Deeper Look at Variables and Data Types:

JavaScript is considered a loosely typed language, meaning variables can hold different types of data. For example:
Code

          var x = "hi";
          x = 0;
         console.log(x);
          //output : 0
      
In the previous example, a variable was created and assigned string data, and then the variable was reassigned with another type of data, a number. JavaScript can determine the type of the variable based on the data it holds at the current moment and perform operations accordingly. For example, numeric data (number) can have arithmetic operations performed on it, such as:
Code

      var x = 5;
      console.log(x + 1);
      //output: 6
  
- What if we try to add a string variable? In this case, the two strings will be concatenated, which is a merging operation between two strings, such as:
Code

          var x =" my name is ";
          console.log(x + 'ahmed');
          //output:  my name is ahmed
    
- What if we try to add a number to a string? In this case, JavaScript will not consider the + sign as an addition operator but as a concatenation operator between two strings, such as:
Code

          var x = 10;
          console.log(x + 'ahmed');
          //output: 10ahmed
    
- How can we change the value of a variable itself through an arithmetic or logical operation? For example, how can we add 5 to a variable with a value of 10 to make the variable's value 15? This can be done as follows:
Code

          var x = 10;
          x = x + 5
          console.log(x);
          //output: 15
    
You can also increment a numeric variable by 1 using x++ or ++X as follows:
Code

    var x = 10;
    x++;
    console.log(x);
    //output: 11
  
Or
Code

          var x = 10;
          ++x;
          console.log(x);
          //output:11
    
However, there is a difference between x++ and ++X. When the variable is written first, the variable is reassigned with its current value and then incremented by 1. But if we write ++ first and then the variable name, the variable's value will be incremented first and then reassigned. For example:
Code

          var x = 10;
          console.log(x++);
    
In this example, the result in the console will be 10 because the code printed the variable's value first and then incremented it by 1 in memory. However, in this code:
Code

          var x = 10;
          console.log(++x);
    
In this example, the output will be 11 because the code incremented the variable by 1 first and then printed it.

You can also use x-- and --x to decrement a variable by 1.

- You can determine the type of data stored in a variable using typeof, such as:
Code

          var x = 10;
          console.log(typeof x);
          //output: number
    
And
Code

          var x = true;
          console.log(typeof x);
          //output: boolean
    
While
Code

          var x = 'true';
          console.log(typeof x);
          //output: string
    
- You can also change the data type of a variable. For example, we know that x = 10 is a numeric variable, while x = '10' is a string variable, but it can be converted to a numeric variable. How can we change it from a string to a number? Using parseInt:
Code

          var x = '10';
          x =  parseInt(x);
          console.log(typeof x);
          //output: number
    

February 27, 2025

Read More
إقرأ المزيد

المنافسة السعرية و فخ التسليع

Price Competition and the Snare of Price Erosion

دورة تدريبية

Course

2/2/1/1 أساسيات الجافاسكريبت 'التعامل مع الأرقام'

1/1/2/2 JavaScript fundamentals 'Working with Numbers'

التسويق الرياضي في أندية الشركات و صناعة الجماهيرية

Sports Marketing in Corporate Clubs and the Fanbase Industry

دورة تدريبية

Course

8/2/1/1 أساسيات الجافاسكريبت 'الـ Arrays'

1/1/2/8 JavaScript fundamentals 'Arrays'

مشكلة التسويق الرقمي بين الإختزال و الأوهام

The Problem of Digital Marketing Between Reductionism and Illusions

Keywords
كلمات مفتاحية

دورة تطوير المواقع الإلكترونية دورة الـ mean-stack from a to z mean-stack دورة الـ دورة النود بالعربي دورة الأنجولر بالعربي

web development coursecourse mean-stack from a to zcourse mean-stack from a to zmean-stack coursenode js arabic courseangular arabic course

© 2026 Ahmed Zayed. All rights reserved.© 2026 كل الحقوق محفوظة أحمد زايد