When I started learning JavaScript, the first two concepts I learned were variables and functions. They are the foundation of every JavaScript program.
What is a Variable? 📦
A variable is a container that stores data.
let name = "Narasimma";
const age = 21;
console.log(name);
console.log(age);
let → Value can change
const → Value cannot be changed
What is a Function? ⚙️
A function is a reusable block of code that performs a specific task.
function greet(name) {
return "Hello " + name;
}
console.log(greet("Student"));
Output:
Hello Student
Why Use Functions?
Instead of writing the same code many times, create one function and reuse it whenever needed.
Top comments (0)