Skip to content

Instantly share code, notes, and snippets.

@geastwood
Last active August 29, 2015 14:03
Show Gist options
  • Save geastwood/8650b0896adfaa4d74d5 to your computer and use it in GitHub Desktop.
Save geastwood/8650b0896adfaa4d74d5 to your computer and use it in GitHub Desktop.
strict mode
  • this will not refer to window object
  • callee, caller of arguments object are not allowed under strict mode
  • under strict mode parameter is not refereced linked to arguments object, no strict mode, parameter is a reference of the arguments object.
(function() {
    var nostrict = function(x) {
        arguments[0] = 'modified';
        console.log('arguments[0] =', arguments[0]);
        console.log('x=', arguments[0]);
        console.log('under non-strict mode,', x === arguments[0]); // log true
    };
    var strict = function(x) {
        'use strict';
        arguments[0] = 'modified';
        console.log('arguments[0] =', arguments[0]);
        console.log('x=', arguments[0]);
        console.log('under strict mode', x === arguments[0]); // log false
    };
    nostrict('unmodified');
    strict('unmodified');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment