Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

How to learn JavaScript coding on a Mac

Lucy Hattersley | June 3, 2016
Discover how to use the JavaScript scripting language on your Apple Mac, with our simple tutorials and recommended online courses

So you want to learn JavaScript? That's a good idea! JavaScript is the most popular programming languages around, topping Stack Overflow's 2015 developer survey with 54.4 percent of programmers using it. And it works well on Mac, too.

If you're looking to learn to program, then JavaScript is a great choice. Unlike Pythonor C, it's a scripting language and works in conjunction with other technologies. You'll use JavaScript alongside HTML and CSS to create interactive elements for websites.

JavaScript is one of the first programming languages you should learn. It follows on quickly from HTML and CSS, and you learn the fundamentals of programming while quickly creating impressing websites that show off your new-found skills.

Learn JavaScript in OS X: Setting up JavaScript

JavaScript is an interpreted language. You don't compile JavaScript programs and run them (in the sense that you do in C). Instead, you write code and attach it inside HTML (the language used to display content on websites).

Like HTML, the requirements for writing JavaScript programs are simple. You need a text editor and a web browser. Safari is fine as a web browser, but we don't advise creating code in TextEdit because it doesn't save as text files.

Here are some programs you should consider if you're going to learn JavaScript (and web development in general).

It's a good idea to install the Firebug extension for Firefox. Lots of JavaScript developers use the Firebox extension to inspect HTML and modify the code in real time. You won't need it at first, but it'll come in handy as you progress.

Create Hello world in JavaScript

It's traditional to create your first program to display "Hello, World!" on the screen. Displaying the words is even easier in HTML, but this JavaScript program (inside a HTML file) creates an alert on the screen, displaying "Hello World":

Open your text editor and enter the following code:

How to learn JavaScript in Mac OS X

Save this file to your desktop as "helloworld.html". Now drag the file on top of the Safari icon in your Dock (or open Safari and choose File > Open File).

When the browser reads the HTML document, it'll interpret the JavaScript code and run the program. You place JavaScript code inside HTML using the  tags.

Hello World in Javascript on a Mac


1  2  Next Page 

Sign up for CIO Asia eNewsletters.