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?..)

6

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.