2

I am trying to validate the JavaScript on my website. The scripts do not throw any errors and run fine on Chrome and Firefox (latest stable version). However, the animated parts absolutely do not work on IE (9)[*1][*solved]. I have used jQuery and jQueryUI for the animation and had hoped that it would be cross browser compatible.

Usually I would not have cared abut IE users, but liked the idea of folks at anybrowser.org and thought of sticking to a standard instead of using the lowest common denominator and leave the graceful degradation to the browsers / JS engines. My page is HTML5 compliant according to the w3c validator and I wanted to do the same with JavaScript, but could not find an acceptable way to do it.

Why JSLint did not work -

  1. It will not take the page and check it like w3c validator.
  2. So there is no way to check jQuery referenced script. (There are a few SO posts on this).

I did find an ECMA-264 test page that would check the browser, but not my JavaScript.

The question after all the preamble is: How do I validate the Javascript on my webpage? Is there an authoritative validator for JavaScript?

*1 Added: The minification has nothing to do with the script not working on IE9. Even the unminified version does not work.

*Solved: The problem with the specific page was solved by this comment.


This started as "What is Javascript?" got closed here and migrated to Programmers. Thanks to YannisRizos for helping me to split the original question to something that was acceptable between Programmers and SO.

Community
  • 1
  • 1
Lord Loh.
  • 2,437
  • 7
  • 39
  • 64
  • 2
    If only compliant to a standard meant it would work universally everywhere. I want to move to such a magical and wondrous place. – Alex Wayne Oct 23 '12 at 00:19
  • The only reliable HTML standard is HTML 4.01. More recently, there are various [HTML5 drafts](http://www.w3.org/TR/html5/) and an [HTML living standard](http://www.whatwg.org/specs/web-apps/current-work/multipage/). Good luck with finding even one browser that is "compliant with HTML5", much less all browsers in use. There is no standard for "JavaScript", there is only the ECMAScript Language specification, EMCA-262. – RobG Oct 23 '12 at 01:10

1 Answers1

3

A test suite. No really.

If you want to ensure your javascript runs perfectly in every target environment, then you write a test suite for your code and make sure it passes in all your target environments.

A test suite helps find where your code breaks when run on different platforms. And therefore helps you fix it.


But assuming you want something that is less work, http://www.jshint.com/ is your best bet.

Or http://www.jslint.com/ if you like getting yelled at.

But honestly, no validator will ever be able to ensure that your code runs without error and exactly how you expect everywhere. Simply because your code follows best practices correctly, that doesn't mean it will work in an old version of IE.

Standards evolve, but an old browser that never updates get stuck with whatever standard was out at the time that the browser maker may or may not have even implemented successfully or accurately.

Testing, automated or manual, is the only way to ensure things work universally.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
  • http://programmers.stackexchange.com/questions/170935/what-is-javascript-really/170944#comment328070_170944 comment actually pointed out the problem with my page. I do not expect it to work on old IEs, but I would have been happy to have a standard, sticking to which I could hope to have graceful degrading and get better with with future browser releases. – Lord Loh. Oct 23 '12 at 00:35
  • A validator or standard or set of best practices might have helped. You just seemed to expect something that finds all the flaws in your code, and nothing can really do that. – Alex Wayne Oct 23 '12 at 00:42
  • Are you suggesting I should rephrase my question an an alternative way? To make it less ambiguous ? – Lord Loh. Oct 23 '12 at 00:46
  • 1
    The question is clear. **jshint** or **jslint** is the _closest_ thing to what you seem to want. But I think the reason the thing you _really_ doesn't exist is because it would have far less value than you think. It's easy to validate markup like HTML or CSS, because the syntax is so constrained and simple. But you can't validate executable code in the same way. And least not in any way that guarantees very much real world quality or portability. – Alex Wayne Oct 23 '12 at 00:54
  • Okay. I get your point now. Executable Code! I am not a CS student. things like these seem to take a while to strike :-/ I was looking at things like just checking grammar - syntax checker. Thank you! – Lord Loh. Oct 23 '12 at 00:57