This is a draft cheat sheet. It is a work in progress and is not finished yet.
JavaScript Basics
Including JavaScript in an HTML Page |
<script type="text/javascript"> //JS code goes here </script> |
Call an External JavaScript File |
<script src="myscript.js"></script><code></code> |
Including Comments |
// comment here : Single line comments /* comment here */ : Multi-line comments |
Variables in JavaScript
var, const, let : |
var : The most common variable. Can be reassigned but only accessed within a function. Variables defined with var move to the top when code is executed. |
const : Can not be reassigned and not accessible before they appear within the code. |
let : Similar to const, however, let variable can be reassigned but not re-declared |
Data Types : |
var age = 23 : Numbers var x : Variables var a = "init" : Text (strings) var b = 1 + 2 + 3 : Operations var c = true : True or fase statements const PI = 3.14 : Constant numbers
|
Objects : |
// Example 1 var name = {firstName:"John", lastName:”Doe"} // Example 2 var person = { firstName:"John",{ lastName:"Doe",{ age:20,{ nationality:"German" }; |
|
|
|
|
|