Basics
Including External JavaScript : Type 1
.
Including External JavaScript : Type 2
.
Writing Inline JavaScript
.
x = 1; will throw an error because the variable is not declared.
ES 2015+
Constants – Immutable Variables
Variables which cannot be re-assigned new content.
.
Template Strings
.
: Allows binding using pattern matching, with support for matching arrays and objects.
.
DOM Manipulation
Returns a reference to the element by its ID.
document.getElementById(id);
.
Returns an object array of all child elements which have all of the given class names.
document.getElementById(id);
.
Returns an HTML Collection of elements with the given tag name.
document.getElementsByTagName(name);
.
Returns the first element within the document that matches the specified group of selectors.
document.querySelector(selectors);
.
Returns a list of the elements within the document (using depth-first pre-order traversal of the document’s nodes) that match the specified group of selectors.
document.querySelectorAll(selectors);
Create new elements
var btn = document.createElement(“BUTTON”);
.
Example: Create an element and append some text
var header = document.createElement(“H1”);
var text = document.createTextNode(“Hello”);
header.appendChild(text);
.
header.classList.remove(“foo”,”bar”); . Add or remove a class alternatively header.classList.toggle(“visible”); . Check if an element has a class, return true if it does or false if not header.classList.contains(“foo”); .
Math & Numbers
Outputting Data
Arrays Basics
Basics
.
Different ways to add items to an array
.