I use the "Closure Compiler" , while compiling my scripts I spend the following:
Before compiling:
// ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS // @output_file_name default.js // @formatting pretty_print,print_input_delimiter // ==/ClosureCompiler== var myObj1 = (function() { var undefined; //<----- declare undefined this.test = function(value, arg1) { var exp = 0; arg1 = arg1 == undefined ? true : arg1; //<----- use declare undefined exp = (arg1) ? value * 5 : value * 10; return exp; }; return this; }).call({}); var myObj2 = (function() { this.test = function(value, arg1) { var exp = 0; arg1 = arg1 == undefined ? true : arg1; //<----- without declare undefined exp = (arg1) ? value * 5 : value * 10; return exp; }; return this; }).call({});
Compiled by:
// Input 0 var myObj1 = function() { this.test = function(b, a) { a = a == void 0 ? true : a; //<----- var c = 0; return c = a ? b * 5 : b * 10 }; return this }.call({}), myObj2 = function() { this.test = function(b, a) { a = a == undefined ? true : a; //<----- var c = 0; return c = a ? b * 5 : b * 10 }; return this }.call({});
With this, I believe that the question of using "void 0" and "undefined" is there a difference in use or two cases is good ?.
Edit
if I define "var undefined" compiled with "void 0", if I do not define "undefined" compiled with "undedined." then there is no question of the number of characters between "undefined" and "void 0"
Test
Edit II: performance based on this link
Code and test
IE 8:
Type: 228ms
undefined: 62ms
void 0: 57ms
Firefox 3.6:
Type: 10 ms
undefined: 3ms
void 0: 3ms
Opera 11:
typeof: 67ms
undefined: 19ms
void 0: 20ms
Chrome 8:
Type: 3 ms
undefined: 5ms
void 0: 3ms
javascript google-closure google-closure-compiler
andres descalzo Jan 26 2018-11-11T00: 00Z
source share