Why is my remote function not of type "undefined" in Node.js?

I am using Node.js.

After my β€œsum” function is removed, I expect typeof (sum) to return β€œundefined”, but that is not the case.

// functions are data in Javascript

var sum = function ( a,b ) { return a + b; }
var add = sum;
delete sum;
console.log ( typeof sum ); // should return undefined
console.log ( typeof add ); // should return function
console.log ( add( 1,2 ) ); // should return 3

I would have thought that he should return:

undefined
function
3

But instead, it returns:

function
function
3
+5
source share
2 answers

You should not use the operator deletefor identifiers (in scope variables, functions - like sum- or function arguments).

The purpose of the operator deleteis to remove the properties of the object.

, , , .

, . , delete , ES5 , delete sum; ReferenceError.

Edit

@SLacks, delete Firebug, Firebug eval , , , , eval, , , , , eval, :

eval('var sum = function () {}');
typeof sum; // "function"
delete sum; // true
typeof sum; // "undefined"

, :

firebug-eval-code

, , , , eval.

+12

delete , .

, .

EDIT: , , , Firebug, . :

, -, Eval, . , DontDelete, . Firebug .

+11

All Articles