Function Without brackets ( )



  • alt text
    If you've been introduced to programming for a considerable period of time, you would know what functions are. In programming, function can be told as a code segment which has a specific name and carries a specific task.Usually they return a value.

    After creating a function, you execute the function, then it does the part of work which is given to it.If you have learned OOC (object oriented concepts), functions are known as methods.

    Functions we learn in C++, Java, python like main programming languages always have a bracket/parenthesis- ( ).
    We get used to see these functions as a code segment associated with brackets, parameters, a body{}, and return values. So it's a bit complex thing when you enter to the beginning period of programming life.

    But now, in our era, today, one of the most powerful programming language is JS, JavaScript. It has the ability to contain a whole function in one variable or it's just a one word.

    e.g:-

             var Vehicle = function (a){
                              return a;
                           }
    

    now Vehicle object is also a function when you use it. So it can be used even as a argument in another function.

    And also there are some ways to invoke/call a function in JS without using parenthesis.
    e.g:-As constructor

              function cat(){
                    console.log('meow');
              }
    

    With new you can invoke a function without parentheses:

                                        new cat; // parentheses are optional in this construct.
    

    There are many more interesting, easy-peasy features we can use in JS.
    We can discuss an learn them in L</>D.Or may be next post is yours 🙂

    P.S. image from web.