DEV Community

BekmuhammadDev
BekmuhammadDev

Posted on

Javascript

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;



Enter fullscreen mode Exit fullscreen mode

Create and call a function:



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



Enter fullscreen mode Exit fullscreen mode

Working with arrays:



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



Enter fullscreen mode Exit fullscreen mode
  • 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

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
cansole

Image description

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

cansole

Image description

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

Image description

cansole

Image description

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
cansole

Image description

Top comments (0)