0

Just discovered some weird error that reads:

Uncaught ReferenceError: symbol is not defined

Code in question:

const symbol='tNEOUSD';
function get_position(symbol=symbol){
    console.log(symbol);
}
get_position();

How come it's not defined? That's a really weird!

On the other hand if I use a different parameter name it works just fine:

const symbol='tNEOUSD';
function get_position(sym=symbol){
    console.log(sym);
}
get_position();

Does anyone know why this happens?

Anonymous
  • 4,692
  • 8
  • 61
  • 91
  • 4
    Defaults are evaluated when the function is called, and with parameters up to and including themselves in scope. Kind of like writing `let x = 5; { let x = x; }`. – Ry- Mar 08 '18 at 12:41

1 Answers1

-2

You cant use a variable which is already declared outside as a parameter. enter image description here

ZMXX
  • 21
  • 3
  • 1
    That message seems to refer to previously having used `const symbol` or `let symbol` in your session. The code in that painting works standing alone. – Bergi Mar 08 '18 at 12:50
  • 1
    @ZMXX please [be nice](https://stackoverflow.com/help/be-nice) – Bugs Mar 08 '18 at 12:53