DEV Community 👩‍💻👨‍💻

Dharchini
Dharchini

Posted on

JavaScript function

A JavaScript function is a section of code created to carry out a certain purpose. When "something" calls a JavaScript function, it is carried out (calls it).

Syntax of JavaScript Functions

A JavaScript function's definition consists of the function keyword, a name, and parentheses (). Function names may also include underscores, dollar signs, and other characters (same rules as variables). Names of parameters may be included in parenthesis and separated by commas:
(parameter1, parameter2, ...)

Curly brackets enclose the code that the function will execute: {}

The function definition lists the function arguments between parentheses (). When a function is called, values are sent to it as arguments.

The arguments (the parameters) operate as local variables within the function.

let x = myFunction(4, 3); // Function is called, return value will end up in x

function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}

Top comments (0)

Dark Mode?

🌖🌗🌘 Turn on dark mode in your DEV Settings