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.
1.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
2.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
3.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!
4.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
5.String Concatenation
We combine (concatenate) strings using +
.
⮞ Example:
let firstName = "Alex";
let lastName = "Smith";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: Alex Smith
6.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!!!
Top comments (0)