Is it possible to overwrite the undefined in javascript?

后端 未结 3 834
萌比男神i
萌比男神i 2021-01-02 14:02

like

function myFunction(){
    var undefined = \"abc\";
}

If its possible then how to restrict not to allow that?

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 14:43

    Some browsers allow it, the best way to restrict it is avoiding it.

    But... some are using this technique to preserve the undefined:

    (function(undefined){
    
    })()
    

    They get a variable called undefined but don't pass a value which gives undefined the undefined value.

    From jQuery's source code:

    (function( window, undefined ) {
        ...
        ...
    })(window);
    

提交回复
热议问题