Function in Javascript

 Function in Javascript

In this article we are goanna to see about Function in Javascript and where we use these. which is most important when you are going to start your career in JavaScript. Please read and enjoy this article if you want to give any feedback about your experience, we welcome.



A function is a block of code designed to perform a particular task.

A function is executed when "something" invokes it (calls it).

A 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).

Function Invocation (Call function):

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)

Syntax:

function function_name(){

            statement;

    }

function_name();

Ex:

function myfunction(){

        document.write(“Hello”);

    }

myfunction();

Share:

0 comments

Please leave your comments...... Thanks