Javascript
Tags: javascript, frontend, aripovdev
Published: 2024-06-23 00:55:35

JavaScript is a high-level, interpreted programming language, primarily the power to make web pages interactive. This language bug was introduced in 1995 by Brendan Eich for Netscape. JavaScript is now supported by all modern browsers and is expanding.

Key Features of JavaScript:

1. Dynamic and interpretable: JavaScript code is executed directly by the browser and does not require pre-compilation.
2. High-level programming language: JavaScript has a high level of abstraction, meaning that code written in this language can be easily understood and written by humans.
3. Object-Oriented Programming: JavaScript supports an object-oriented model that allows code to be modular and non-repetitive.
4. Functional programming: JavaScript treats functions as first-class citizens, which can be passed to or returned as arguments to other functions.

The main areas of use of JavaScript are:

1. Web Development: JavaScript is used in conjunction with HTML and CSS to make web pages interactive. Allows you to manipulate HTML elements through the DOM (Document Object Model).
2. Server-side programming: The Node.js platform allows JavaScript to be used for server-side programming as well.
3. Mobile Apps: Frameworks like React Native, Ionic, and PhoneGap allow you to develop mobile apps using JavaScript.
4. Game development: JavaScript is used to create web games using libraries such as Phaser.

Basic concepts of JavaScript

1. Variables: The var, let, and const keywords are used to declare variables in JavaScript.
2. Data Types: The main data types are number, string, boolean, object, undefined, and null.
3. Operators: There are arithmetic, comparison, logical and other operators.
4. Functions: Syntax for creating and calling functions.
5. Arrays: To store data in the form of a list.
6. Objects: Store data as key-value pairs.

JavaScript examples:

```
let name = "Alice";
const age = 30;

```

Create and call a function:

```
function greet(person) {
    return "Hello, " + person + "!";
}
console.log(greet("Bob")); 

```

Working with arrays:

```
let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[1]); 

```

- Loops
- for loop
- while
- do while
- Functions (Declaration)

SCOPES:
Scopes are divided into 4 types:
1-Global scope
2-Local scope
3-Function scope
4-Block scope

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjlpuu1q89hw30lb0te8.png)

Global scope — The place where all code is written

Local scope — the area around the function

Function scope — the part inside the function

Block scopes — If you write something, for example: if else or for

**LOOPS**:

There are 3 loop operators that are mainly used in JavaScript.

1-while
2-do while
3-for operatorlari:

**While** recursive operator:while operation

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2e7kk6yblxsjfu780n0.png)
**cansole**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwkbb0r7fiub6e564tkv.png)

**Do while** works the same as while, the difference is that it checks the condition at the end: the operation of do while


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/997lig75dtlsqw6qgq5e.png)

**cansole**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z398zkb9niyk1z9xmtaq.png)

**FOR** The for loop works faster than other loops, is a universal loop and is used a lot:
How the game works:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/081mgci8u9a6fogk58lh.png)

**cansole**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv591oqzn3dicaomjn9z.png)

**FUNCTION DECLERATION**
Fuction declaration => The basis of this function is that we can create a pilus function and call it wherever we want.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/um60lotdblmsy5etaeey.png)
**cansole**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ljit757p73ycqpay92v.png)