Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:19:23+00:00 2026-06-14T08:19:23+00:00

I recently watched a JavaScript video tutorial containing code similar to this one: (function

  • 0

I recently watched a JavaScript video tutorial containing code similar to this one:

(function (){
    var b = 10,
        c = 20, 
        d = 50;

    var e = function(){
        return b + c + d;
    };
    return e();
}());

This is a common JS coding pattern.
The author said that this is an example of a procedural approach in Javascript code. I don’t understand that, can you please explain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:19:25+00:00Added an answer on June 14, 2026 at 8:19 am

    Let’s start by saying the above is a self-invoking anonymous function:

    A self-invoking anonymous function runs automatically/immediately when you
    create it and has no name, hence called anonymous.

    The above is a fairly poor example in my opinion, but consider the following change:

    var f = (function (){
        var b = 10,
            c = 20, 
            d = 50;
    
        var e = function(){
            return b + c + d;
        };
        return e();
    }());
    
    ​console.log(f);​ 
    

    We’ve taken the above code and added a var f = in front of the function. This returns the value of e() from the inner function to f and now you have a value f to be used elsewhere. Since the variables b, c, d, e are declared within the function scope of the anonymous function, we can ensure that they will not be tampered with. This is a way to do private variables in JavaScript. Now say you had 10 + 20 + 50 may places within your code. You could run this anonymous function at the beginning and substitute those occurrences with f. This idea of abstracting out code into various procedures is why it’s referred to as Procedural Programming.

    Procedural programming uses a structured approach to coding the
    program where the functionality of the program is broken down into a
    number of functions
    or subroutines to make it easier to follow and
    reduce the need to repeat code.

    This is mainly used to make code easier to read, easier to follow/debug and lets you abstract commonly used chunks of code into well written snippets of code. 


    Read more


    Self-Invoking Functions

    Purpose of Self-Invoking Functions

    Procedural Programming

    More Procedural Programming

    and this moves you into Closures

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't get my site to use gzip compression. I recently watched this video
I recently watched a video demonstrating that a red5 application with only stub code
I have recently watched this video of a Finnish internet security expert. Somewhere around
I recently watched a good video with regards to a modular JavaScript architecture including
I recently watched this youtube tutorial on the Null Object design pattern. Even though
Recently i watched a video about CRUD operations in mysql and one of the
I watched this webcast recently, and I got the sense that a lot of
I have recently watched a video of Nicholas Zakas talk about high performace scripts.
Recently, we discovered odd behavior in some old code. This code has worked for
I recently watched Douglas Crockford's JavaScript presentations , where he raves about JavaScript prototype

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.