Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • An Overview To Some Useful Terms Used In JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.39k
    Comment on it

    Hello readers,

    InBelow in this blog I will discuss some terms used in JavaScript with their meaning and the context in which they are used.

     

    So here they are :-

     

    • Arity :- The term Arity basically means to refer the number of arguments operands used in a function.

     

    So it is used to return the number of expected arguments in a function. Though this property is no longer used and has been replaced by “length”.


    Below is the function showing an arity of 3 :-

    function getName(first, middle, last){
    
    return first+' '+ middle +' '+last;
    
    }

     

    • Anonymous :- The term “Anonymous” means that the thing or person’s name is unidentified. But in JavaScript this term refers to the function that is not identified by name.

     

    The Anonymous functions are dynamically declared at runtime.

    These are declared using function Operator instead of using Function Declaration .

     

    Below is an example showing the use of this function:-
     

    var flyToTheMoon = function()
    
    {
    
    alert("Zoom! Zoom! Zoom!");
    
    }
    
    flyToTheMoon();
    
    

    As in this example, there is no name after the keyword function.

     

    • Closure :- The Closure function in JavaScript is a function which access to the parent scope, even when it has been closed.

     

    The Closure function takes the parameter along with it and brings back the variable inside the function from where it is not allowed.

    Below is the simple example showing the use of Closure function:-

    
    function order() {
    
    var food;
    
    function waiter(order) {
    
    chef(order);
    
    return food;
    
    }
    
    function chef(order) {
    
    if (order === 'pasta') {
    
    food = ['pasta', 'gravy', 'seasoning'];
    
    cook();
    
    }
    
    }
    
    function cook() { food.push('cooked'); }
    
    return waiter;
    
    }
    
    var myOrder = order();
    
    console.log(myOrder('pasta'));
    
    // Array [ "pasta", "gravy", "seasoning", "cooked" ]

     

    In this example, everything apart from waiter and its return value inside from the order function can be seen.

     

    • Currying :- It is a way of passing all the arguments as expected by the function itself and then passing a subset of those arguments back to the function.

    In simple words, we can say that using multiple functions with single arguments.

    Below is an example showing the use of currying function :-

    var add4 = addx(4);
    
    console.log(add4(8)); //12
    
    console.log(add4(6)); //10
    
    console.log(add4(-74)); //-70
    
    

    In this we can set the sequence of operation which is helpful to get the same variable used in operation.

     

    • Hoisting :- The term hoisting in JavaScript means moving the variables and functions declaration to the top of  their containing scope such that the variables that are declared in a function can be found anywhere in the function.

     

    Below is the code showing the use of hoisting :-

    var name = 'Velma';
    
    console.log(sayCatchPhrase(name)); //"Jinkies!"
    
    
    function sayCatchPhrase(name) {
    
    phrases = {
    
    'Fred Flintstone': 'Yabba dabba doo!',
    
    'Velma': 'Jinkies!',
    
    'Razor': 'Bingo!',
    
    'He-Man': 'I Have the Power'
    
    };
    
    return phrases[name];
    
    }

     

    So, we can write a code for function call before the function declaration using hoisting

    Conclusion:-

    Hence, I hope we have got a brief description about some useful terms used in JavaScript.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: