Zum Inhalt springen

Day 1 – Session 2: JavaScript Basics (Datatypes,Variables, Functions & More)

Hello Devs! ✌️

In today’s session, we’re diving deeper into JavaScript fundamentals. If you’re just getting started, this will help set a solid base. Let’s break it down simply.

📌 Datatypes:

JavaScript has different types of data you can work with. The most common are:

String→ text → "Hello World"
Number → numbers → 42, 3.14
Boolean → true/false → true, false
Undefined→ no value assigned
Null → intentionally empty
Object → key-value pairs → {name: "Alex"}
Array→ list of items → [1, 2, 3]

⮞ Example:

let name = "Alex"; // string
let age = 25; // number
let isStudent = true; // boolean

📌 Variables:

We store data in variables. In modern JS, we mostly use:

let → value can change
const→ value cannot change (constant)

⮞ Example:

let city = "New York";
city = "London"; // this works

const country = "USA";
// country = "Canada"; // ❌ error

📌 Functions

A function is a reusable block of code that performs a task.

⮞ Example:

function greet() {
    console.log("Hello!");
}

We call or invoke a function like this:

greet(); // Output: Hello!

📌 Return & Arguments

Functions can take arguments (inputs) and return outputs.

⮞ Example:

function add(a, b) {
    return a + b;
}

let sum = add(5, 3); // sum = 8
console.log(sum); // Output: 8

📌 String Concatenation

We combine (concatenate) strings using +.

⮞ Example:

let firstName = "Alex";
let lastName = "Smith";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: Alex Smith

🚀Quick Recap

Datatypes help define the kind of data.
Variablesstore data.
Functions let us organize reusable logic.
Arguments & returnallow input and output.
Concatenation connects strings.

That’s a wrap for Session 2!

Thanks for reading — happy coding!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert