Introduction
Functions help us organize code into small, reusable pieces. They make programs easier to read, fix, and reuse.
Functions help us organize code into small, reusable pieces. They make programs easier to read, fix, and reuse.
function functionName(parameters) { // code to run }
Functions start with the keyword function, followed by a name and parentheses.
Code inside curly braces { } runs when you call the function.
function sayHello() { console.log('Hello!'); }
function add(a, b) { return a + b; }
This program uses a function to greet different people by name. It shows how functions help reuse code.
function greet(name) { console.log('Hello, ' + name + '!'); } greet('Alice'); greet('Bob');
Functions keep your code DRY (Don't Repeat Yourself).
They make it easier to fix bugs because you only change code in one place.
Functions let you reuse code easily.
They help break big tasks into smaller steps.
Functions make your code cleaner and easier to understand.
function greet() { console.log('Hello!'); }greet function can be called many times to print 'Hello!' without repeating code.sayHi in JavaScript?function followed by the name and parentheses.function add(a, b) {
return a + b;
}
console.log(add(3, 4));add takes two numbers and returns their sum.function greet() {
console.log('Hello!')
}
greet;greet; which does not execute it.greet();greet; to greet(); -> Option BPass the test and this pattern moves unknown