#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    30
    Rep Power
    6

    Question How to run/test JavaScript?


    Hello,

    I'm reading David Flanagan's "JavaScript: The Definitive Guide, 6th ed".

    It only actually tells users how to run JS code on page 311, where users are told of the following solutions:

    "Client-side JavaScript code is embedded within HTML documents in four ways:

    • Inline, between a pair of <script> and </script> tags
    • From an external file specified by the src attribute of a <script> tag
    • In an HTML event handler attribute, such as onclick or onmouseover
    • In a URL that uses the special javascript: protocol
    ."

    I was wondering what professional JS developers use to write and test their code: Do they use a good text editor with syntax high-lighting + autocompletion, hit F5 in the browser to reload the page every time they make a change, and use some add-on in the browser to investigate errors? Or are there full-fledged IDE's similar to MS VisualStudio for non-web languages?

    Thank you.
    --------
    <strike>Edit: For instance, I wrote this piece of code, which doesn't work (nothing displayed on screen when calling index.html), but Firefox doesn't display any error. How would I go trying to understand why it's not working?</strike>

    Firebug showed that a .js file shouldn't contain <script>...</script> lines.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    10
    Are you using an external script file?

    If you are using an external stylesheet, you don't need to add the <script> tags.

    I use WAMP since I started PHP so I use it all the time to test anything really. I use Firefox and Firebug and like you said, especailly javascript I always do a hard refresh (F5) after changing anything to make sure it's still working.

    Also, try putting a console.log() statement with variables to check their value.

    Hope this helps,

    Regards

    NM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    30
    Rep Power
    6
    Thanks for the input.

    So the standard tools used by JS developers:
    - Firefox and the Firebug add-on
    - a good text editor with syntax highlighting, and ideally code autocompletion
    - hit F5 to test every time a change is made to the JS source code
    - console.log() statement with variables to check their value.

    Could someone recommend a good text editor for Windows that supports JS code autocompletion?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    10
    Number 1: is a 100% must in my opinion and I think in most developers opinions.

    Number 2: I agree with using an editor with syntax highlighting but I don't think autocompletion is a necessity. Each to their own but that kind of thing annoys me.

    Number 3: This is what I do and it's mainly because i'm relatively new to javascript. I skimmed the surface off it a couple of years ago but never got into any real depth. I've taken it up again in the last month or so.

    Number 4: I only console.log() something if I get an unexpected result, for instance I might get an error in firebug, or sometimes the console.log() might not work inside a function so I know if it's a passed parameter then the issue could potentially be there so it even gives you an idea of where the error could lie. I think it will log most errors for you.

    hope this helps.

    Kind regards,

    NM.

IMN logo majestic logo threadwatch logo seochat tools logo