0 day streak
javascript / beginner
Snippet

Basic Function Declaration

Functions are reusable blocks of code. You define them with the 'function' keyword, provide parameters, and use 'return' to send a value back.

snippet.js
javascript
1
2
3
4
5
function add(a, b) {
return a + b;
}
const result = add(5, 3);
console.log(result);
nodejs
Breakdown
1
function add(a, b) {
Defines a function named 'add' that takes two inputs: a and b.
2
return a + b;
Calculates the sum and exits the function with that value.