0

I tried writing image: HTMLImageElement in my browser console today. I expected an error would occur, but it didn't.

This does not declare a variable as var image: HTMLImageElement on TypeScript does, and it also does not define a property as var x = { image: HTMLImageElement } does. It seems that this actually does nothing. What does this syntax do?

Kagami Sascha Rosylight
  • 1,412
  • 1
  • 14
  • 31
  • 1
    You just created a [label](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label) called `image` – CodingIntrigue Aug 18 '14 at 13:50
  • 1
    possible duplicate of [What does ':' (colon) do in JavaScript?](http://stackoverflow.com/questions/418799/what-does-colon-do-in-javascript) ([this answer](http://stackoverflow.com/a/418865/660921)) – Martin Tournoij Aug 18 '14 at 13:50
  • Oh, I didn't know that JavaScript also has labels! Thank you for everyone. I have searched and found that post, but it seems I scrolled the page down too quickly. – Kagami Sascha Rosylight Aug 18 '14 at 14:36

1 Answers1

1

Unless within an object, text followed by a colon in JavaScript is a labelled statement. An example labelled statement which you will have probably seen before is:

<a href="javascript: void(0)">

In this case, javascript is the label and void(0) is the statement. In your case, image is the label and HTMLImageElement is the statement.

James Donnelly
  • 126,410
  • 34
  • 208
  • 218