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)
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!
August 23rd, 2015 at 13:16
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.
August 24th, 2015 at 15:18
Thanks for the tip Maarten :-)
July 21st, 2015 at 16:08
I also like using W3C School’s Editor. For example:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_objects_create_2
July 23rd, 2015 at 17:50
Hi Felipe
Thank you for the tip and the link :-)
August 10th, 2015 at 18:12
Here’s another tool where you can try out JavaScript, on-line: JS Fiddle. The link is to the tutorial page, in the documentation. The actual editor is here.