0% found this document useful (0 votes)
3 views2 pages

functions in java script

Functions in JavaScript are essential for performing specific tasks and promoting code reusability and organization. They can be defined using the function keyword, with parameters listed in parentheses and executable code within curly brackets. Function invocation occurs through events, direct calls, or automatically, allowing the defined code to execute.

Uploaded by

Lakhan Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

functions in java script

Functions in JavaScript are essential for performing specific tasks and promoting code reusability and organization. They can be defined using the function keyword, with parameters listed in parentheses and executable code within curly brackets. Function invocation occurs through events, direct calls, or automatically, allowing the defined code to execute.

Uploaded by

Lakhan Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Functions in JavaScript are fundamental building blocks of code designed to

perform specific tasks. They allow for code reusability, organization, and
modularity within a program.
Defining Functions:
Functions can be defined in several ways: Function Declarations.

JavaScript Function Syntax


A JavaScript function is defined with the function keyword, followed by
a name, followed by parentheses ().

Function names can contain letters, digits, underscores, and dollar signs (same
rules as variables).

The parentheses may include parameter names separated by commas:


(parameter1, parameter2, ...)

The code to be executed, by the function, is placed inside curly brackets: {}

function name(parameter1, parameter2, parameter3) {


// code to be executed
}

Function parameters are listed inside the parentheses () in the function


definition.

Function arguments are the values received by the function when it is


invoked.

Inside the function, the arguments (the parameters) behave as local variables.

function myFunction(p1, p2) {


return p1 * p2;
}

Function Invocation
The code inside the function will execute when "something" invokes (calls) the
function:

 When an event occurs (when a user clicks a button)


 When it is invoked (called) from JavaScript code
 Automatically (self invoked)

You will learn a lot more about function invocation later in this tutorial.

You might also like