music

JavaScript Music Theory


Project maintained by ronyeh

Music Theory + JavaScript

This tutorial demonstrates basic music concepts in JavaScript. All code on this page is MIT licensed.

To follow along, install the following package:

npm install go-music

The source code can be found here.

Note

A note is one tone played at a single pitch. When you strike a piano key, or pluck a guitar string, you are playing a note.

Notes have letter names, like A, B, C, D, E, F, G.

Using our JS library, you can learn the relationships between the notes:

showNote('A');

Here’s a fun website where you can explore notes: https://learningmusic.ableton.com/notes-and-scales/notes-and-scales.html

Chord

showChord('C major');
showChord('C major 1st inversion');
showChord('A minor');

Interval

An interval is the distance between two notes.

showInterval('C', 'A');

Staff

A staff is a set of horizontal lines and spaces that represent music.

Here is an example staff showing four chords to be played in sequence:

Staff

let s = new Staff();
s.addClef('treble');
s.addChord('C4', 'F4', 'A4').withDuration(1/4);
s.addChord('C4', 'E4', 'Bb4').withDuration(1/4);
s.addChord('C4', 'E4', 'G4').withDuration(1/4);
s.addChord('C4', 'F#4', 'A4').withDuration(1/4);
showStaff(s);

See

More Resources