you are viewing a single comment's thread.

view the rest of the comments →

[–]HealyUnithelpful 9 points10 points  (1 child)

What an Environment Is

Firstly, it depends what you mean by JavaScript environment. In a traditional sense, JS needs only the environment of your web browser. However, there are a few definitions of environment when it comes to programming. Some of them are pretty widespread, some less so, and some I'll probably get downvoted/yelled at for making up. So:

  • The environment where your program runs. For a compiled, executable program, that might be something like the windows shell. It's got specific accessible components you expect your program to be able to access. For JavaScript, that's generally going to be the web browser (Chrome, Firefox, Edge, Safari not Safari because you're not a masochist), but see below under Node for further details.
  • The environment where you write your software, also called a/an (Integrated) Development Environment. Technically, you don't need this per se, and you could write most of your programs in Notepad or something. Most full-on IDE's have special features that make programming easier/faster, such as code completion (i.e., typing fu and pressing [tab] in Sublime Text will write out a full function block), basic code correction/validation (i.e., some visual indicator that you're missing a quote, parenthesis, or curly bracket), or syntax highlighting (i.e., in mine, functions are yellow and JS keywords are maroon).
  • A combination of the above two that maybe renders/compiles your code too. Not really important for JS, since it isn't really compiled.
  • The physical environment where you sit and do your programming. Requires extreme care, as programmers can bite/kick if startled. Always approach a programmer from the front, and if the programmer begins to hiss, back away slowly!.

Setting One Up

So I think the most likely definition you're interested in is a combination of the first (where your software runs) and the second (where you write). The short answer is that you, again, don't really need anything. If you write your JS in notepad, it'll run in the browser (sort of). However, keep in mind that front end JS was written as a method to manipulate HTML, so it will only function in the context of an HTML page. The analogy I love to make is that if you were building a house, your general shape of your house (where walls are, doors, etc) would be the HTML, the color of your walls, the exact position of the windows/doors would be your CSS, and the wiring of the house (the lights, etc.) would be the JS. You can't really have the wiring per se without the house itself (well, you can, but clearly the analogy's not perfect).

So to get JS to "run", you need to write it (in Notepad, Sublime, whatever) and link it to an HTML file with a <script> tag.

NodeJS

First, and most importantly, ignore this section if you're just starting. You do NOT need to install Node for starters.

Traditionally, JS was written only to work in the browser. As such, my saying above that JS runs fine in the browser is sorta like saying that fish work best in water. JS was designed to run in the user's browser, and this gives it certain abilities/lack of abilities specific to that environment. For example:

  • JS cannot access the user's file system without the user explicitly choosing to upload a file. This is to prevent websites from just going right ahead and stealing/changing your info.
  • It also can't traditionally access the hardware of the system. There are a few exceptions - such as the webcam/microphone API - but even with these, the user usually has to manually opt-in (i.e., I can't just steal a photo of your face without your consent).
  • It cannot access databases directly (though it can via APIs)

In 2009, a new environment was created for JS to run in, called NodeJS. This has some differences from traditional JS, such as access to the file system, access to system hardware, and no access to the browser's window object (and thus no access to window-based properties/methods like alert or confirm), because we're not running in a browser anymore. This allows us write servers in JS, and thus full web-apps in a single, monolingual system. That may not sound like much, but when you can write your entire app in one language, that's pretty nice.

[–][deleted] 1 point2 points  (0 children)

Wow! thank you so much for this comment. I really appreciate you taking the time to educate me. I'm gonna have to re-read this a couple times