๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—˜๐˜…๐—ฝ๐—น๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฑ

Functions are blocks of code. They perform specific tasks. You write them once and use them many times.

Why you need them:

How a function works:

You define a function with the function keyword. You give it a name. You add parentheses. You put the logic inside curly brackets.

A function does nothing until you call it. You call a function by using its name and parentheses. The parentheses tell the computer to execute the code now.

Syntax structure:

function name(parameter1, parameter2) { // code goes here }

Functions handle input and output:

You can store returned values in variables for later use.

Local variables:

When you declare a variable inside a function, it is local. This means only the code inside that function sees it. Other parts of your program cannot access it.

Local variables follow a simple lifecycle:

This allows you to use the same variable name in different functions without causing errors.

Source: https://www.w3schools.com/js/js_function_intro.asp

Full post: https://dev.to/vidhya_murali_5aabe7784bd/functions-in-javascript-38h8