Programming Languages
JavaScript
Subjective
Sep 25, 2025
What are JavaScript functions?
Detailed Explanation
JavaScript functions can be defined in several ways:
1. Function Declaration:
function greet(name) {
return "Hello " + name;
}
2. Function Expression:
const greet = function(name) {
return "Hello " + name;
};
3. Arrow Function (ES6):
const greet = (name) => {
return "Hello " + name;
};
// Or shorter:
const greet = name => "Hello " + name;
4. Constructor Function:
const greet = new Function("name", "return 'Hello ' + name");
Functions are first-class objects in JavaScript, meaning they can be assigned to variables, passed as arguments, and returned from other functions.
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts