Javascript hoisting example

<head>
&lt;title&gt;Hoisting example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1>Hoisting in action&lt;/h1&gt;
    &lt;script type="application/javascript"&gt;
        var hoisting = "global variable";
        (function(){
            confirm("\"" + hoisting + "\"" + " click OK" );
            var hoisting = "local variable";
            alert(hoisting);
        })(); //self-executing function

     //Best practice - declare local variables at the beginning of the function
    &lt;/script&gt;
&lt;/body>
Subscribe to our newsletter for more code resources and news

Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being

Mongo create full text index example

Code snippets showing how to create a mongo create full text index and how to search for results with its help. Continue reading

Mongo full text search example

Published on February 07, 2021

Mongoose query pagination example

Published on February 05, 2021