Function
A function in JavaScript is a reusable block of code designed to perform a specific task. It can take inputs (parameters) and return an output.
Function Declaration
a function should be declared by their name and the function name should be called at end to specify tasks.
Types of Function
Named Function
function drive()
{
console.log("car");
}
drive();
o/p - car
Function Expression
let drive = function() {
return 'car';
}
console.log(drive());
o/p - car
Anonymous function
const drive = function() {
return "Drive slowly";
};
console.log(drive());
o/p - Drive slowly
Arrow function
let add = (num) => num + 2;
console.log(add(5));
o/p - 7
Top comments (0)