JavaScript Cheatsheet

Ever have trouble recalling the exact syntax for your favorite HTML code? Give it a permanent home and add it to this page! Select any snippet below and it'll automatically select all of the code for you to copy.

HTML link to JavaScript

This is how you link to your JavaScript file inside HTML

<script src="script.js"></script>
  

JavaScript Variables

In JavaScript, the equal sign (=) is an "assignment" operator, not an "equal to" operator.

var price1 = 5;
var price2 = 6;
var total = price1 + price2;
  

Console Log

The console.log() method writes a message to the console.
The console is useful for testing purposes.

var myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.log(myArr);