Starting Javascript

Why Javascript?

Javascript is quickly becoming regarded as the language that is the future of the internet. We've been learning Ruby, which is comparatively easy to learn and necessary for learning Rails, but any true web programmer must know Javascript. Not only will Javascript be useful for your coding career, but learning another language is educationally beneficial as well. The process gets easier the more you practice (kind of like how learning Italian is much easier if you know Spanish), so the sooner you get started, the better!

Running Javascript on your Computer

The Browser Developer Console

Javascript comes built-in with every modern web browser, like Google Chrome. To launch Chrome's Javascript console, on the menu go to View -> Developer -> Javascript console (Command-option-J or Ctrl-alt-J). You can start typing Javascript right there; try console.log("hello world");. What do you see? Why does it output two lines of output?

In Your Shell

While the console is good for trying quick and dirty snippets of Javascript, it's annoying for running long files. To do that, we'd like something like the ruby command in our shell. The Javascript equivalent is called node.js.

Most Javascript programmers have node installed on their computer, so we'll follow suit. Go to nodejs.org and install node onto your machine using the appropriate installer. If everything works properly, you should be able to open your shell (Terminal or cmd prompt) and type node. If you see a >, then type console.log("hello world");. What do you see? Why? Is it the same or different than in the browser?

Start Writing Javascript

You may have noticed above that node behaves a lot like irb or pry does for Ruby. node also behaves like the actual command ruby: we can use it to run a specific Javascript file. Create a sub-folder in your iX folder called javascript. (How you structure this folder will be left up to you—a large part of coding is being able to stay organized and coming up with a system for not getting lost in a sea of files.) In javascript, create a file called, unsurprisingly, hello_world.js. In it, type console.log("hello world");. Save it, and then run it in your shell the same way you would run a Ruby file: cd to the new directory, then type node hello_world.js. What is the output? Is it the same or different than what you saw in the browser or node prompt? If it's different, why do think it is so?

Back to the Beginning

Now you know how to make and run Javascript files—all that's left to do is to learn Javascript. As a coder, one of the best skills you can have is the ability to teach yourself coding languages. This is your opportunity to practice! Starting from the beginning of the course, do the Ruby exercises, but in Javascript. Some things will be easier, somethings will be much harder, but impossible is nothing. Use Google, StackOverflow, and other internet resources to guide you. Only if you're truly stuck, as a teacher for help.

A good place to familiarize yourself with Javascript basics is the Codecademy Javascript track. The beginning is very easy and may be tedious, so skip ahead as you feel necessary.