Tuesday, 23 June 2015

javascript basic again


var a = 12;

without "var" a is a global variable! you can assess it from functions and different packages.

-------
== and ===

== is a value compare     1 == "1" will return true
1 === "1" will return


---------

function scope.

var xx = function(){
var aa = "aa"
if (true) {
var bb = "bb";

};
alert(bb);
}

the result is "bb"

-------

global scope




(function(){
    var a = 12
    var inner = function(){

    }

    window.fn = inner;
})();

fn()  // this function is a global function.


Another way to call a function after it created:  (self executing function)

!function (){
}()

-----
self executing function is useful with "window", like jquery srouce code does. And it can create private variables for jquery library and jquery's author don't need worry about conflicting with users' variables.



http://markdalgleish.com/2011/03/self-executing-anonymous-functions/










No comments:

Post a comment