How to create a function in JavaScript?

How to create a function in JavaScript?

A function is also a block a code which when called performs an action or returns a value. Functions are declared with the keyword “function”. It is followed by a name and ends with parentheses(), The name of function follows the same rules as variables. It can contain letter, numbers, underscores and dollar signs. The parentheses can be used for optional parameters. The code of the function which is to be executed is included inside the curly brackets { }.

function name(optional parameters) {
    code to be executed

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.