3

I apologize if this question is stupid or duplicated, please point me to the right direction if so.

I've tested this code:

function b()
{
    a: 22;
    return a;
}

Code returns no error. Which leads me into thinking a: 20 inside function works. Though when call the function:

b();

..I receive "ReferenceError: a is not defined"

What does a: 22 inside function actually do? this.a inside function returns nothing so I don't think it has something to do with function as object (or it does?..)

user8555937
  • 2,161
  • 1
  • 14
  • 39

1 Answers1

2

The a: 22 in your code is a label – it labels the statement 22 with the identifier a.

From MDN:

The labeled statement can be used with break or continue statements. It is prefixing a statement with an identifier which you can refer to.

Read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

Daniel Diekmeier
  • 3,401
  • 18
  • 33