2

I have written a:bc = 9 in javascript.

when i `console.log(bc) its printing 9

but when I console.log(a) it gives "a" is not defined.

could anyone help me understand what is happening here?

charan
  • 41
  • 5
  • Sorry, couldn't reproduce the described behavior. Could you fix it? – Leonardo Alves Machado Sep 28 '22 at 16:56
  • 2
    `console.log(a:cv)` is invalid syntax; `a:bc = 9` is just a label [What does the JavaScript syntax foo: mean?](https://stackoverflow.com/q/39655737) – VLAZ Sep 28 '22 at 16:57
  • hi, made changes could you look at it again? – charan Sep 28 '22 at 16:58
  • 1
    Does this answer your question? [What does the JavaScript syntax foo: mean?](https://stackoverflow.com/questions/39655737/what-does-the-javascript-syntax-foo-mean) – Leonardo Alves Machado Sep 28 '22 at 16:59
  • no buddy if "a" is the label and when I am logging it, it should not throw any error, right? – charan Sep 28 '22 at 17:02
  • 2
    You cannot log a label. It *will* throw an error if you try to log it. However, your description does not make sense, since `console.log(a:bc)` would *also* throw an error. It cannot log anything. Without a [mcve] it seems you're not showing real code. – VLAZ Sep 28 '22 at 17:05
  • actually am working with REPL, hence the confusion, but got it, thanks for the explanation :) – charan Sep 28 '22 at 17:09
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label – axiac Sep 28 '22 at 17:27

1 Answers1

4
a:bc = 9

As per ECMAScript only a:bc = 9 its just a label and the last bc gets assigned to 9 and a will not have any effects.

console.log(bc); // 9 only this statement will work
sasi66
  • 437
  • 2
  • 7