6

I started learning JavaScript a while ago. It's a fairly easy programming language considering that I learned Java in university, that I know php pretty well and that I already played around with python and ruby. The problem is that to properly learn a programming language I usually create a project. In javascript, I just don't know what kind of project I could create - that is, a project that is not web-based or related to the web browser. Can I create javascript shell scripts? Where is javascript commonly used beside the web browsers?

So, can someone actually give me some ideas please?

Robert Audi
  • 8,019
  • 9
  • 45
  • 67
  • Believe it or not, a *very similar* question was just asked by another user: http://stackoverflow.com/questions/2528508/if-i-want-to-learn-javascript-by-small-project-what-should-i-do If that answers your question, recommend deleting this one. If not, suggest posting back to say you've read it but are still looking for ideas. – T.J. Crowder Mar 31 '10 at 12:10
  • JavaScript is an EASY language... I guess it depends how you use it... I think that could be said for any language... its "easy" if you use it to write a Hello World application... – Zoidberg Mar 31 '10 at 12:11
  • Zoidberg: Javascript is a small language, but it takes infinite amount of time to learn the in's and out's of it. Closures, Prototypical Inheritance, etc etc. – Matt Mar 31 '10 at 12:14
  • 1
    @Zoidberg & @Matt: I think you're both right. It's an easy language to pick up, and a demanding (and rewarding) language to master. – T.J. Crowder Mar 31 '10 at 12:23
  • Thanks for all the answers! I have work to do now: javascript shell scripts, OS X Dashboard widgets and HTA applications it will be! – Robert Audi Mar 31 '10 at 12:33
  • @T.J. Kinda like what they say about Poker, 15 minutes to learn, a life-time to master. – Zoidberg Mar 31 '10 at 13:41
  • @Zoidberg: Yeah. :-) Poker, Chess, Go... – T.J. Crowder Mar 31 '10 at 13:47

5 Answers5

5

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • @T.J. Crowder This all sounds very nice, but how on earth can javascript execute shell command lets say "uptime" in *nix, with what will you execute it? if you have php file you can execute it with `php file.php` , how do you execute javascript? `javascript file.js` ? I think you can't or perhaps I don't know how – ant Mar 31 '10 at 12:47
  • @c0mrade: It depends on what interpreter you're using to make it happen. For instance, on Windows, you can use the various WSH objects to do that. If using Rhino, you'd use the `java.lang.Process` or similar. I'm sure `jsc` provides functionality along these lines. You're confusing *language* with *runtime environment*. :-) – T.J. Crowder Mar 31 '10 at 13:09
  • yea totally, tnx for the explanation though – ant Mar 31 '10 at 13:15
  • @c0mrade: Actually, sorry, I think I misunderstood your question. You can run a JavaScript files as a shell script on Windows in the way I explain in my answer. On *nix, the usual thing would be to set up an interpreter (for instance, it could be `/bin/javascript` if you like) and then use `#!/bin/javascript` at the top of the script to tell the command interpreter what to run it with (this is just like with python and others). That would refer to `jsc` (probably) on a Mac, could refer to Rhino on Linux, or something else. There are lots of JavaScript interpreter projects out there. :-) – T.J. Crowder Mar 31 '10 at 13:40
4

windows Sidebar Gadgets, Apple's Widgets, and Google Desktop Gadgets are all created using HTML/ JS/ CSS.

I learnt Javascript by creating a few small Windows Sidebar Gadgets.

Getting Started

Sidebar Reference

Matt
  • 74,352
  • 26
  • 153
  • 180
2

You could use javascript to make HTA (HTML Applications) that can be run outside of the the web browser sandbox.
MSDN intro to HTA Applications
Javascript Tutorial on HTML Applications

Terrance
  • 11,764
  • 4
  • 54
  • 80
1

You could write a non-blocking TCP server. Node.js supports that.

Ivo Danihelka
  • 3,382
  • 3
  • 31
  • 27
0

Common uses of javascript outside of browsers are WSH scripts and HTA applications on Windows and Dashboard widgets on Mac.

user187291
  • 53,363
  • 19
  • 95
  • 127