function

What is function ?

  • Profile picture of Mcs
  • by Mcs June 30, 2025

A function in JavaScript is a block of code designed to perform a specific task. You can reuse a function wherever you need it, which helps keep your code clean and efficient.

Function Structure:

1. Function Declaration (named function)

Function Declaration

 2. Function with Parameters

Function with Parameters

3. Function with Return Value

Function with Return Value

4. Function Expression (anonymous function)

Function Expression (anonymous function)

 5. Arrow Function (ES6)

Arrow Function (ES6)

A function can be called any number of times, and it only runs when called.

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.