Can I create javascript shell scripts?
You bet!
- On Windows, you can do this by using
cscript.exe
(you can even set up a file extension -- I use jx
-- that automatically runs when you just double-click the filename or use it as a command in a shell: Just associate that file extension with the command "c:\WINDOWS\system32\cscript.exe" /e:JavaScript /nologo "%1" %*
). This is (and I've measured carefully) about 80 milion times better than fighting with Windows' batch language. About. (And if you don't want to use JScript — Microsoft's variant of JavaScript — you even have options, see below.)
- On *nix, a shell script can be set to run in any installed interpreter (that's what the
#!...
line at the top is telling the command interpreter). I expect you'll find a few if you search around.
- On the Mac, you probably have JavaScriptCore installed in
/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
- And on all of the above, if you like, you can install Rhino and Java and get platform independence and access to a huge range of library functionality. Rhino has a built-in shell, or you can tell it to execute a specific JavaScript file. It interoperates with Java, so if you do this, you have easy access to all essentially of the functionality available to Java.
Where is javascript commonly used beside the web browsers?
I use it for shell scripting on Windows. I also use it as a server-side language, for instance in the server-side part of a web application. It's also used in other environments where a lightweight, powerful scripting language is useful, such as in the MongoDB shell environment (you can use it to query MongoDB data) and stored procedures.
All of that said, writing a browser-based project is a rich, interactive way to learn the language.