Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Advertisements

Functions

Declarative vs. Dynamic Functions

In JavaScript, functions can be categorized into two main types:

  • Declarative/Static Functions: These functions have a fixed structure and are not redefined during runtime.
  • Dynamic/Anonymous Functions: These functions can be evaluated multiple times, and they can be anonymous or dynamically created.

Defining Functions

There are different ways to define functions in JavaScript:

  • Using the Function Constructor:

    var variable = new Function("param1", "param2", ..., "paramn", "function body");

    Functions created with the Function Constructor are parsed every time they are evaluated.

  • Using Function Literal:

    var func = (params) => {
        // statements;
    };

    This type of function, defined using a function literal, is parsed only once, making it a more efficient way of defining functions.

Function Literals

When a function is used within an expression in another statement, it is considered a function literal, regardless of the expression it is used in.

Function Properties

JavaScript functions have certain properties that can be accessed:

  • functionName.length: This property returns the number of arguments expected by the function.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x