Skip to content

Instantly share code, notes, and snippets.

@chaffeqa
Created April 15, 2016 02:33

Revisions

  1. chaffeqa created this gist Apr 15, 2016.
    13 changes: 13 additions & 0 deletions callbacks.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    function meth1(){
    return 1;
    }
    function meth2(input){
    return 2 + input;
    }
    function result(arg1, cb){
    var result = typeof(cb) == "function" && cb(arg1)
    return result
    }
    console.log('a'+result(1,meth1()))
    console.log('b'+result(1,meth1))
    console.log('C'+result(1,meth2))
    16 changes: 16 additions & 0 deletions closures.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    (function() {
    var a = b = 5;
    })();
    console.log(b);
    // What will be printed on the console?

    (function(a,b,c) {
    console.log(a,b,c)
    })(window, document);
    // What will be printed on the console?


    (function f(f){
    return typeof f();
    })(function(){ return 1; });
    // what is the result?
    15 changes: 15 additions & 0 deletions context.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    var fullname = 'John Doe';
    var obj = {
    fullname: 'Colin Ihrig',
    prop: {
    fullname: 'Aurelio De Rosa',
    getFullname: function() {
    return this.fullname;
    }
    }
    };
    console.log(obj.prop.getFullname());
    var test = obj.prop.getFullname;
    console.log(test());
    // What is the result of the following code?