๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐
Functions are blocks of code for specific tasks. You run them when you call them.
Use functions to:
- Reuse code.
- Organize your work.
- Make code easy to read.
Create a function with the function keyword. Give it a name. Use parentheses. Put your code in curly brackets.
Variables inside a function stay local. Only the function sees them. This lets you use the same name in different functions.
Store function results in variables. Use functions in math or assignments.
How functions work:
- Parameters: send values to the function.
- Arguments: the function receives these values.
- Logic: the function does work.
- Return: the function sends a value back to you.
Source: w3schools.com Optional learning community: https://dev.to/vidhya_murali_5aabe7784bd/functions-in-javascipt-19ei