DEV Community

Matt Tran
Matt Tran

Posted on

3 Things You Need to Know About JavaScript Functions

What should I know about JavaScript functions? Well you're in luck because today we'll go over 3 core topics seen in JavaScript functions.


1. Fundamentals

Q: What is a JavaScript function?
A: A JavaScript function is a block of code that performs specific tasks when called.
Q: Why are JavaScript functions important?
A: JavaScript functions are important because they help keep code organized and efficient.
Q: How are functions declared?
A: Functions are declared with the "function" keyword followed by a function name and parentheses. Functions can then be invoked(also known as "called") by using the function name followed by parentheses, which executes the function.


2. Parameters and Return Values

Q: What are parameters?
A: Parameters are what is written inside the parentheses of a function.
Q: What is the purpose of parameters?
A: Parameters give functions the ability to use values and different inputs for calculations and other tasks.

Q: What are return values?
A: Return values are values that are returned after a function finishes its task.
Q: What is the purpose of return values?
A: Return values are used to get information and execute further actions from the functions output.


3. Callback Functions and Arrow Functions

Q: What is a callback function?
A: A callback function is a function that you use as input to another function.
Q:How are callback functions used?
A: Callback functions are used to specify what happens after another task is completed.
Q: What are arrow functions?
A: Arrow functions are used to make code more concise when defining functions.
Q: How do you write an arrow function in JavaScript?
A: Use the following syntax when writing arrow functions:

const function = (parameter) => {

return result;
};

In this example,

  • 'const' declares the variable for the function
  • 'function' is the function you use
  • 'parameter' is the parameter of the function used
  • '=>' is the arrow function
  • 'return' is the output of the function

If you've followed along, I trust you've grasped the core of JavaScript functions. Best of luck with your coding journey ahead! Happy coding!

Top comments (0)