Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript Your First JavaScript Program

michaelmugo
michaelmugo
3,971 Points

Local JavaScript Execution without dependency on HTML

Is it possible to locally run javascript as a standalone web script instead of it being included to HTML as an external/internal reference?

You could run Node on your desktop computer (instead of a web server) for standalone scripts. What are you trying to accomplish?

michaelmugo
michaelmugo
3,971 Points

I'm trying to run a javascript helloworld.js script from my ide. Was thinking it would be possible like PHP files.

I'm using Webstorm

3 Answers

No. Javascript is like a sub-language within HTML.

Robert Pazo
Robert Pazo
8,884 Points

It may take a little work to get it up and running, but yes it is possible. Check out the link at Mozilla's website https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino Enjoi :)

michaelmugo
michaelmugo
3,971 Points

Thx! It seems very promising

michaelmugo
michaelmugo
3,971 Points

So I decided to finally get clear on this. I researched on the Mozilla Developer Network as it is Officially maintained by them. This is from the JavaScript Wikipedia article.

The key thing on finding out the answer was first determining what it is. From MDN:

JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language.

This took me to the meaning of scripting language (From Wikipedia):

A programming language that supports scripts: Programs written for a special run-time environment that can interpret (rather than compile) and automate the execution of tasks that could alternatively be executed one-by-one by a human operator

This means it can be ran in a wide variety of use cases, from IoT devices, to servers to phones based on the environment being targeted. This means that it can be used both standalone or in an environment, such as a web browser.

Therefore, local execution can be in a number ways, including those mentioned above. But for simplicity's sake embedding it as in the client-side via HTML is the easiest option. Therefore, I could write separate JavaScript files but reference them within my HTML pages. Rhino and Node.js are server-side implementations using a custom JavaScript server or JavaScript engine