Skip to content

yasiirdev/Javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Professional JavaScript Guide (Latest Version)

Introduction

JavaScript (ECMAScript 2023+) is a modern, versatile language for web, server, and app development. It powers interactive websites, APIs, and more.


Table of Contents

  1. What is JavaScript?
  2. Variables & Data Types
  3. Operators
  4. Control Flow (Conditionals & Loops)
  5. Functions
  6. Arrays & Objects
  7. DOM Manipulation
  8. Events
  9. ES6+ & Latest Features
  10. Asynchronous JavaScript
  11. Error Handling
  12. Modules
  13. classNamees & OOP
  14. Best Practices

1. What is JavaScript?

JavaScript is a high-level, interpreted language that runs in browsers and on servers (Node.js). It supports functional, object-oriented, and event-driven programming.


2. Variables & Data Types

let name = "Alice"; // String const age = 30; // Number let isActive = true; // Boolean let user = null; // Null let data; // Undefined let big = 123n; // BigInt let sym = Symbol("id"); // Symbol

3. Operators

  • Arithmetic: +, -, *, /, %, **
  • Assignment: =, +=, -=
  • Comparison: ==, ===, !=, !==, <, >
  • Logical: &&, ||, !
  • Nullish: ??
  • Optional Chaining: ?.

4. Control Flow

Conditionals

if (age > 18) { console.log("Adult"); } else { console.log("Minor"); }

Loops

for (let i = 0; i < 5; i++) { console.log(i); } for (const fruit of fruits) { console.log(fruit); } fruits.forEach((fruit) => console.log(fruit));

5. Functions

function greet(name) { return `Hello, ${name}!`; } const add = (a, b) => a + b; const double = (x) => x * 2;

6. Arrays & Objects

Arrays

const fruits = ["Apple", "Banana", "Cherry"]; fruits.push("Mango"); const [first, ...rest] = fruits;

Objects

const user = { name: "Alice", age: 30, greet() { return `Hi, ${this.name}`; }, }; const { name, age } = user;

7. DOM Manipulation

const title = document.getElementById("main-title"); title.textContent = "Welcome!"; title.style.color = "blue";

8. Events

document.querySelector("button").addEventListener("click", () => { alert("Button clicked!"); });

9. ES6+ & Latest Features

  • Arrow Functions
  • Template Literals
  • Destructuring
  • Spread/Rest Operators
  • classNamees
  • Modules (import/export)
  • Optional Chaining (?.)
  • Nullish Coalescing (??)
  • Private Fields in classNamees (#field)
  • Top-level Await
  • Array at() method
  • Object.hasOwn()
  • Promise.any()
  • Logical Assignment Operators (||=, &&=, ??=)
  • Temporal API (upcoming)

10. Asynchronous JavaScript

Callbacks

setTimeout(() => { console.log("Done!"); }, 1000);

Promises

fetch("/api/data") .then((res) => res.json()) .then((data) => console.log(data));

Async/Await

async function getData() { const res = await fetch("/api/data"); const data = await res.json(); console.log(data); }

11. Error Handling

try { // risky code } catch (error) { console.error(error); } finally { // cleanup }

12. Modules

// math.js export function add(a, b) { return a + b; } // app.js import { add } from "./math.js";

13. classNamees & OOP

className Animal { #privateField = "secret"; constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a sound.`); } } className Dog extends Animal { speak() { console.log(`${this.name} barks.`); } }

14. Best Practices

  • Use const and let (avoid var)
  • Write clean, readable code
  • Use strict equality (===)
  • Keep functions short and focused
  • Handle errors gracefully
  • Comment your code
  • Avoid global variables
  • Use modern features
  • Stay updated with ECMAScript releases

Pro Tip: JavaScript is always evolving. Master the latest features and best practices to write robust, modern code!