🧠 Introduction

JavaScript is a versatile programming language that powers dynamic web pages. It's essential for front-end development and increasingly used for back-end via Node.js. Let's dive into the fundamentals!

🧩 Variables and Data Types

JavaScript uses let, const, and var to declare variables. Common data types include:

  • number (e.g., 42, 3.14)
  • string (e.g., "Hello, World!")
  • boolean (e.g., true, false)
  • array (e.g., [1, 2, 3])
  • object (e.g., { name: "JavaScript" })
variable_declaration

🔧 Operators

Operators let you manipulate data:

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, ===, >, <, !=
  • Logical: &&, ||, !
  • Assignment: =, +=, -=

🧪 Functions

Functions are reusable blocks of code. Example:

function greet(name) {
  return "Hello, " + name + "!";
}
function_declaration

🔄 Control Structures

Control structures dictate the flow of your code:

  • If/Else:
    if (x > 10) {
      console.log("x is large");
    } else {
      console.log("x is small");
    }
    
  • Switch:
    switch (day) {
      case "Monday":
        console.log("Start of the week!");
        break;
      default:
        console.log("Other day");
    }
    

🔄 Loops

Loops repeat code execution:

  • For Loop:
    for (let i = 0; i < 5; i++) {
      console.log(i);
    }
    
  • While Loop:
    let count = 0;
    while (count < 3) {
      console.log(count);
      count++;
    }
    

🧱 Objects and Arrays

  • Objects: Store key-value pairs.
    const person = { name: "Alice", age: 25 };
    
  • Arrays: Ordered lists.
    const fruits = ["apple", "banana", "orange"];
    
array_methods

🚀 Conclusion

Mastering JavaScript basics opens doors to building interactive websites and apps. For deeper exploration, check out our JavaScript Advanced Tutorial.

javascript_ecosystem