VBA->JS: Trying out JavaScript (Tool)

Up until now, you’ve had to take my word that JavaScript behaves the way I describe. That’s fine, for an article or two, but at some point a developer wants to actually try these things out…

Unlike VB6, VB.NET or C# you can’t create an independent program using JavaScript, by itself. Similarly to VBA it needs to run in a host environment, typically a browser window as part of an HTML page. Of course, if you’re just playing around, setting up an HTML page so that you can see the results of your JavaScript tests is a lot of (too much!) work. What’s more, you’re not going to get much information when things go wrong – for the most part the code will simply stop executing.

So I was very happy when one book I was reading recommended using the “Firebug” add-on for the Mozilla Firefox browser.

This installs into the Firefox browser as a button in the toolbar across the top (circled in red in the screenshot, below). Clicking the button opens a split-pane at the bottom of the browser window. On the right, you type the JavaScript code. When you click on “Run” in the tools across the top of the split-pane the code is executed and the result of the last line is printed. This is similar to using the Immediate Window in the VBA Editor, except you can type lines and lines of code in a normal manner rather than everything having to be on a single line. (Firebug1.png)

Firebug add-on in Firefox

Firebug add-on in Firefox

When you get serious about creating applications, such as a Web Add-in for Word or Excel, then you need a different tool – although this still comes in handy for testing things!



5 Responses to “VBA->JS: Trying out JavaScript (Tool)”

  1.   Maarten van Stam Says:

    Personally I like http://www.typescriptlang.org/Playground . This was meant to ‘test’ TypeScript to see how it translates into JavaScript but as TypeScript is fully JavaScript compatible you can just enter JavaScript in there as well.

  2.   Felipe Costa Gualberto Says:

    I also like using W3C School’s Editor. For example:
    http://www.w3schools.com/js/tryit.asp?filename=tryjs_objects_create_2

Leave a Reply