Introduction to JavaScript
What JavaScript is
Section titled “What JavaScript is”JavaScript is the programming language of the web. Every modern browser runs it, which is how a page responds to clicks, checks a form before sending it, or loads new data without reloading. It also runs outside the browser, most often in Node.js, where it is used for servers, command-line tools and build scripts.
The language itself is defined by a standard called ECMAScript, which gains a new edition every year. Browsers and Node.js implement that standard, and each adds its own extra features on top: a browser provides the page (the DOM), events and storage, while Node.js provides files, processes and networking.
Running the examples
Section titled “Running the examples”Most examples in this guide are plain JavaScript and print their results with console.log. They can be run in two ways:
- In a browser. Open the developer tools (F12, or Cmd+Option+I on a Mac), go to the Console tab, paste the code and press Enter.
- In Node.js. Save the code to a file such as
example.jsand runnode example.jsin a terminal.
const items = ['tea', 'milk', 'bread'];console.log(`The list has ${items.length} items.`);This prints:
The list has 3 items.A few pages work with the page itself, such as events and the DOM, and those examples need a browser. The page says so where that is the case.
How this guide is organised
Section titled “How this guide is organised”The guide starts with the basics and builds up, one feature per page. Its groups are:
- Fundamentals: variables,
ifstatements, logical operators, equality and the operators that choose between values. - Arrays: creating arrays and working with their elements.
- Objects: creating objects and reading, adding and removing their properties.
- Loops: repeating work with
for,whileand their variants. - Functions: declaring and calling functions, parameters and return values.
- Variables and data types:
var,letandconst, scope, and the types of value JavaScript has. - Strings: searching, slicing, trimming, padding and building strings.
- Dates: creating, comparing and formatting dates and times.
- Array methods:
map,filter,reduce,findand the other built-in methods. - Maths: rounding, random numbers, number bases and the
Mathobject. - Property configuration: property descriptors, getters and setters, and freezing and sealing objects.
- Iterators and generators: the iteration protocol and generator functions.
- Prototypes: how objects inherit from one another through the prototype chain.
- Promises: asynchronous code with promises and
asyncandawait. - Classes: the
classsyntax and how it relates to prototypes. - Network requests: loading data with
fetch. - Events: listening for and handling events in the browser.
- Code quality: writing code that is easier to read, check and debug.
- Error handling:
try,catchandfinally, and throwing errors. - Regular expressions: matching and replacing text with patterns.
The examples use modern JavaScript: const and let rather than var, arrow functions where they read naturally, template literals and strict equality. Older forms appear only on the pages that are about them.
About this guide
Section titled “About this guide”This guide is written to accompany Steve Griffith’s video series on JavaScript, which is on his YouTube channel, Steve Griffith - Prof3ssorSt3v3. Each page covers a topic from his videos and ends with a link to the matching video, so the page and the video can be used together.
Steve Griffith covers this topic in his video Introduction to JavaScript.