Menu

1 / 2

Functions in JavaScript

DEV Community·PRIYA K·6 months ago
#nJF3IB3f
Reading 0:00
15s threshold

Functions

Reusable block of code designed to perform a specific task.

Fundamental building blocks in JavaScript.

ia similar to procedure -A set of statements to perform a task.

Procedure to qualify as a function , it Take inputs,perform action and return outputs

Use a function,define it somewhere in the scope

Allows to reuse,organise and modlarise code

Defining Functions or Function Declaration

A function definition (also called a function declaration, or function statement) consists of

the function keyword,

The name of the function.

A list of parameters to the function, enclosed in parentheses and separated by commas.

The JavaScript statements that define the function, enclosed in curly braces, { /* … */ }.

function functionName ( parameters ) { // code }

Enter fullscreen mode

Exit fullscreen mode

Example

function square ( number ) { return number * number ; }

Enter fullscreen mode

Exit fullscreen mode

JavaScript passes values in two ways:

Primitive values (like number,…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.