An easy way to learn JavaScript with proper Examples and definition An easy way to learn javascript from scratch

Javascript functions are used for reusability of code and performance

A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
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: {}

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

1. When an event occurs (when a user clicks a button)
2. When it is invoked (called) from JavaScript code
Automatically (self invoked)

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

Local Variables

1. Variables declared within a JavaScript function, become LOCAL to the function.

2. Local variables can only be accessed from within the function.

3. Since local variables are only recognized inside their functions, variables with the same name can be used in different functions.

4. Local variables are created when a function starts, and deleted when the function is completed.

Global Variables


View Github