Today I dev in javascript like most days and it feels good... So I was moving some javascript out of an HTML file and putting it in a javascript file and it work.. after a while, I turn that file into a module and it complain! Can you guess what it complains about? It complains about HTML comments in the module!?!?!?!?
How quirky javascript how quirky... NOW! I wonder how many of you knew about this?!?! And if some high-end language spec person didn't know about this, then it's your job to find the creature of the language and to ask him if he knew of this?!
What a quirky part of javascript.
Of course, everyone who has written some JavaScript 20 years ago used that pattern:
<script><!--
// javascript code here
--></script>
so that browsers that didn’t understand JS would not output the code, while browsers that did understand JS would ignore the HTML comment delimiters and execute the code.
(But why am I suddenly feeling old?)
2 Likes
You know.... I probably saw this already in some old code examples or code period and just.... idk maybe thought it was a browser thing in the webpage as an exception to not render or ignore this script if javascript is not supported... But still... kinda interesting to those who play in the language for a long time but never knew this!
How do you all feel about that typescript's proposal of adding type to javascript with comments? I would think that would be easy to do, but I'm not a language spec specialty or a browser implementor so I wouldn't know.
And once javascript gets typed, will that mean it can be compiled to javascript bit code? In case someone could answer, I don't want to spin up a new topic since this is not even a normal forum to just do that in.
TC39 doesn't have a forum for javascript devs to just ask questions that could have been answered by doing a duckduckgo search but that would be no fun.
Bite code? According to that proposal, no. That proposal is simply trying to carve out some space for people to place arbitrary type syntax in, and different type-parsers can interpret those things differently. With those syntax changes, you could even write something silly like function fn(x: (hello world)) { ... }
, and common type-parsers like TypeScript wouldn't be able to understand it, but you could create your own that interpreted "hello world" as an alias to a number type.
So JavaScript will not be able to understand those types, all it's doing is leaving a place for type syntax to exist.
I'm not a delegate, but I'll share my opinions. I do have mixed feelings, and I wouldn't be surprised if others are feeling the same way. I would like to see some sort of native typing added to JavaScript, but I'm not certain yet if this is the best way to go. We'll see.
If you have further questions about this proposal, you can always file an issue on it as well.
1 Like