Including JavaScript in an HTML Page
HTML
<script type="text/javascript"> //JS code goes here </script>Call an External JavaScript File
HTML
<script src="myscript.js"></script>Including Comments
Single line comments -// Comment Multi-line comments -
/* comment here */Variables
var, const, letvar — 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
Numbers —var age = 23 Variables —
var xText (strings) —
var a = "init"Operations —
var b = 1 + 2 + 3True or fase statements —
var c = trueConstant numbers —
const PI = 3.14Objects —
var name = {firstName:"John", lastName:”Doe"}Objects Example
JavaScript
var person = { firstName:"John", lastName:"Doe", age:20, nationality:"American" };