FUNCTION :
A function is a block of code that performs a specific task and can be reused. There are three ways!
1.Function Declaration,
2.Function Expression,
3.Arrow Function (ES6) (Short syntax, Commonly used in modern JS).
Examples:
1.
function greet(name) {
return "Hello " + name;
}
console.log(greet("Ajmal"));
- const add = function (a, b) { return a + b; };
console.log(add(5, 3));
3.const multiply = (a, b) => a * b;
console.log(multiply(4, 2));
OBJECTS: An object stores data in key-value pairs. It's a combination of state and behavior.
ex:
const person = {
firstName: "John", // Property
lastName: "Doe", // Property
age: 50, // Property
fullName: function() { // Method
return this.firstName + " " + this.lastName;
}
};
OBJECT CON
Top comments (0)