-1

In console:

    >var t = function(undefined){
             return undefined
          }

    >t("ss")
    >"ss"

I dont get why it returns a string. Though

void(0)

always returns undefined

ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • 5
    You've got a function with a parameter called `undefined`, and you pass it a value and return that. You're returning a variable value as you've overridden `undefined` – Reinstate Monica Cellio Mar 27 '18 at 11:33
  • 5
    because `undefined` is not a reserved word. – Kaiido Mar 27 '18 at 11:33
  • Because here 'undefined' has been used as a parameter. And in function definition, javascript gave priority to parameter instead of treating as pre-defined keyword. – Ankush Jain Mar 27 '18 at 11:34
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined – Satpal Mar 27 '18 at 11:34
  • 1
    ADDITIONAL INFO: still, undefined is a property which you can compare to like `x === undefined;` For further information about [undefined](https://www.w3schools.com/jsref/jsref_undefined.asp) and/or [difference to null](https://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript) – gkhaos Mar 27 '18 at 11:40

1 Answers1

3

By setting the parameter name to undefined in the function expression, you mask the global variable that is also named undefined.

When you pass "ss" as the first argument, it is assigned to the local variable undefined.

When you return undefined, you return the value of the local variable undefined which is "ss" since that is what you assigned to it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335