Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we still need <!-- //--> in JavaScript block [duplicate]

Tags:

javascript

Possible Duplicate:
Using HTML comment tag <!— --> still relevant around JavaScript code?

Kind of remember <!-- //--> is used to prevent JavaScript code from being displayed in a lower version of IE. Anyone can provide a link to the article explaining this? Hard to search "<!--" in Google, because it's got stripped off.

And do we still need this in JavaScript block?

Thanks!

like image 524
Adam C. Avatar asked Aug 02 '12 13:08

Adam C.


People also ask

How do you prevent duplicate entries in JavaScript?

Answer: Use the indexOf() Method You can use the indexOf() method in conjugation with the push() remove the duplicate values from an array or get all unique values from an array in JavaScript.

Can a JavaScript set have duplicates?

The Set object lets you store unique values of any type, whether primitive values or object references. you are passing new object not reference so it is allowing to add duplicate.

Does Set remove duplicates JavaScript?

1) Remove duplicates from an array using a SetThe new Set will implicitly remove duplicate elements. Then, convert the set back to an array.

How can we avoid adding duplicate objects in array?

To prevent adding duplicates to an array:Use the Array. includes() method to check if the value is not present in the array. If the value is not present, add it to the array using the push() method. The array will not contain any duplicate values.


2 Answers

Those comments were used when Javascript was first introduced. They are not needed any more, and haven't been for quite a while.

The purpose was to hide the script from browsers that didn't even know what the script tag was for. Those browsers would ignore the script tag and show the code inside as regular HTML content.

There are no browsers left that don't know about the <script> tag, so even if they don't run the script, they still don't show the code inside.

like image 92
Guffa Avatar answered Sep 19 '22 10:09

Guffa


Only if you're worried about time-travellers from somewhere back in last milennium coming to the present day with their old computers.

like image 29
Niet the Dark Absol Avatar answered Sep 19 '22 10:09

Niet the Dark Absol