Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

Jesdavpet Seiderson
Jesdavpet Seiderson
21,489 Points

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