cover-img

Javascript Function: Understanding the Basics

14 January, 2023

1

1

0

Contributors

Traditional function

Functions are blocks of code that are structured to perform a specific action. These blocks of code are created to be reusable. The way or form of writing a function is as follows:
The code above cannot be directly copy-pasted, but is only a form of writing a function. A function generally performs an action and before the function ends, the function can return a value by adding the return syntax.
We can also send values into a function by listing them in the brackets in the function's writing. To send more than one value, use a comma as a separator.
Example

Function 1: Simple function without return

Function 2: Simple function with return

Function 3: Function with parameter

Function 4: Sending more than one parameter

Function 5: Initializing parameter with default value

Arrow Function

JavaScript arrow functions, also known as "fat arrow" functions, are a shorthand notation for writing functions in JavaScript. They were introduced in ECMAScript 6 (ES6) and have a more concise syntax compared to traditional function expressions.
The basic syntax of an arrow function is as follows:
Here, the "fat arrow" => is used to define the function, and the keyword const is used to declare the function. If the function does not take any parameters, you can leave the parentheses empty.
Keep in mind that arrow function have some differences with traditional function like: - They don't have their own "this", "arguments", "super", or "new.target".
- They can't be used as constructors.
- They don't have prototype property.
You can check more details about arrow function on this link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Summary

In summary, functions are blocks of code that are designed to perform a specific action and can be reused multiple times. They have a specific syntax, which includes the keyword "function", a name for the function, and a set of parameters that are passed into the function. Functions can also return a value or an expression. JavaScript arrow functions, also known as "fat arrow" functions, are a shorthand notation for writing functions in JavaScript. They were introduced in ECMAScript 6 (ES6) and have a more concise syntax compared to traditional function expressions. Arrow functions don't bind their own 'this' value, instead they inherit the 'this' value of the enclosing context. They are particularly useful for passing callback functions, where the value of 'this' needs to be inherited from the enclosing context. Arrow functions also have some differences with traditional function like : they don't have their own "this" , "arguments" , "super" , or " new.target " . They can't be used as constructors. They don't have prototype property.

1

1

0

Toniebe

Bekasi,Indonesia

Just call me Ebe

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.