شارك البودكاست

المتغيرات و الكائنات في جافا اسكريبت | الجزء الثاني

my instgram: www.instagram.com/codices6/

my spotify: open.spotify.com/show/6SmOwZlltLrYBhdMa18AJ6

code :

3.1 Variables and Data Types

Variables are used to store and manipulate data in JavaScript. Here are the key concepts related to variables and data types:

3.1.1 Variable Declaration and Assignment

– Use the `let` keyword to declare a variable that can be reassigned later.

– Use the `const` keyword to declare a constant variable that cannot be reassigned.

– Example:

javascript

let name = “John”;

const age = 25;

3.1.2 Data Types

JavaScript has several built-in data types, including:

– Numbers: Numeric values, such as `3`, `3.14`, or `1000`.

– Strings: Textual values enclosed in quotes, such as `”Hello”` or `’World’`.

– Booleans: Logical values `true` or `false`.

– Arrays: Ordered lists of values, enclosed in square brackets, such as `[1, 2, 3]`.

– Objects: Key-value pairs enclosed in curly brackets, such as `{ name: “John”, age: 25 }`.

– Null: Represents the absence of any object value.

– Undefined: Represents an uninitialized variable.

3.2 Operators and Expressions

Operators allow you to perform operations on variables and values. Here are some commonly used operators:

3.2.1 Arithmetic Operators

– Addition: `+`

– Subtraction: `-`

– Multiplication: `*`

– Division: `/`

– Modulus (Remainder): `%`

– Example:

javascript

let x = 10;

let y = 5;

let sum = x + y; // 15

let product = x * y; // 50

3.2.2 Comparison Operators

– Equal to: `==`

– Not equal to: `!=`

– Greater than: `>`

– Less than: `<`

– Greater than or equal to: `>=`

– Less than or equal to: `<=`

– Example:

javascript

let a = 10;

let b = 5;

console.log(a > b); // true

console.log(a == b); // false

3.2.3 Logical Operators

– AND: `&&`

– OR: `||`

– NOT: `!`

– Example:

javascript

let sunny = true;

let warm = true;

console.log(sunny && warm); // true

console.log(sunny || warm); // true

console.log(!sunny); // false

3.3 Control Flow and Conditional Statements

Conditional statements allow you to control the flow of execution based on certain conditions. Here are two commonly used conditional statements:

3.3.1 If Statement

– Executes a block of code if a specified condition is true.

– Example:

javascript

let hour = 12;

if (hour < 12) {

console.log(“Good morning!”);

} else {

console.log(“Good afternoon!”);

}

3.3.2 Switch Statement

– Evaluates an expression and executes different code blocks based on different cases.

– Example:

javascript

let day = “Monday”;

switch (day) {

case “Monday”:

console.log(“Start of the week”);

break;

case “Friday”:

console.log(“End of the week”);

break;

default:

console.log(“Some other day”);

}

3.4 Functions

Functions allow you to group and reuse blocks of code. Here’s an example of defining and calling a function:

javascript

function greet(name) {

console.log(“Hello, ” + name + “!”);

}

greet(“John”); // Hello, John!

3.5 Arrays and Objects

Arrays and objects are used to store and manipulate collections of data.

3.5.1 Arrays

– Arrays store multiple values in a single variable.

– Example:

javascript

let numbers = [1, 2, 3, 4];

console.log(numbers[0]); // 1

3.5.2 Objects

– Objects store key-value pairs.

– Example:

javascript

let person = {

name: “John”,

age: 25,

city: “New York”

};

console.log(person.name); // John

Summary:

– Variables are used to store and manipulate data in JavaScript.

– JavaScript has various data types, including numbers, strings, booleans, arrays, and objects.

– Operators and expressions allow you to perform operations on variables and values.

– Conditional statements like `if` and `switch` control the flow of execution based on conditions.

– Functions allow you to group and reuse blocks of code.

– Arrays and objects are used to store and manipulate collections of data.

Homework:

– Practice writing JavaScript code that uses variables, data types, operators, conditional statements, and functions.

النشرة الأسبوعية مساءً كل يوم سبت من اختيار المحررين

نشرة أسبوعية مسائية من بودكاست فلسطين تصلُك إلى بريدك الإلكتروني، تُقدِّم أمتع وأفضل الحلقات من أكثر من ٣٠٠ برنامج بودكاست عربي نختارها لك لتستمع وتستمتع وتتعلّم.

Series Navigation<< مخترع لغة جافا | James Goslingجافا اسكريبت الاحداث و الاخطاء| الجزء الثالث >>