Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 26, 2022 10:37 pm GMT

Review Functions in JavaScript

A function is a reusable block of code that groups together a sequence of statements to perform a specific task.

A function declaration :

Image description

A parameter is a named variable inside a functions block which will be assigned the value of the argument passed in when the function is invoked:

Image description

To call a function in your code:

Image description

ES6 introduces new ways of handling arbitrary parameters through default parameters which allow us to assign a default value to a parameter in case no argument is passed into the function.

To return a value from a function, we use a return statement.

To define a function using function expressions:

Image description

To define a function using arrow function notation:
Image description

Function definition can be made concise using concise arrow notation:

Image description

Its good to be aware of the differences between function expressions, arrow functions, and function declarations. As you program more in JavaScript, youll see a wide variety of how these function types are used.


Original Link: https://dev.to/kibetamos/review-functions-in-javascript-2ap5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To