Skip to content

Latest commit

 

History

History
29 lines (17 loc) · 1.43 KB

File metadata and controls

29 lines (17 loc) · 1.43 KB

Function with JavaScript

Functions are "self contained" modules of code that accomplish a specific task. Functions usually "take in" data, process it, and "return" a result. Once a function is written, it can be used over and over and over again.

JavaScript provides functions similar to most of the scripting and programming languages.

In JavaScript, a function allows you to define a block of code, give it a name and then execute it as many times as you want.

fun

Defining functions:

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: {}

def

Invoking a JavaScript Function:

  • The code inside a function is not executed when the function is defined.

  • The code inside a function is executed when the function is invoked.

  • It is common to use the term "call a function" instead of "invoke a function". call