Javascript: First Steps

📄 BetterWays.dev wiki page | 🕑 Last updated: Feb 9, 2022

undefined

You can use this guide as a quick and simple way to learn Javascript, or as a quick JS reference guide.

At least some prior programming knowledge is required. Due to its clumsy design, I wouldn't recommend learning JS as your first language anyway (it will be later hard to get rid of some bad assumptions you'll build in the process).

OK, let's start with some basic syntax. If you've ever used any C-like language, JS syntax will look very similar.

Hello world

Javascript supports both single and multi-line comments:

/* 
   This is an example of a
   multi-line comment 
*/
// This is an example of a single-line comment

console.log('Hello world');

Semicolons at the end of statements are mostly optional, but, at least for now, I recommend using them anyway, to avoid problems like this:

// this is fine
console.log("a")
console.log("b")

// this is not: TypeError: console.log(...) is not a function
console.log("a")
(() => { console.log("b") })()

Javascript is not white-space sensitive, and blocks are delimited with { ... } brackets.

OK, let's get more practical. The best way to learn JS is to experiment with the REPL. The nice thing about JS is that you already have it in your browser, so you can just press F12 to get a very nice REPL, where you can copy&paste any of these examples.

The alternative is to install node.js (see https://nodejs.org/en/download/) and then you can use:

node script.js
node //open REPL

Let's explore which data types we have available.

Data Types >


Comments and suggestions

You can use this form to submit a suggestion or a comment.

If you find this site useful, please consider supporting it. Supporters also get access to some extras.