JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.
Writing instructions for your computer to execute at a later time.
- The Content Layer (HTML)
- The Design Layer (CSS)
- The Interactive Layer (JavaScript)
- Adding Fancy Page Interactions - here
- Full Featured Web Apps - here
- Drawing & Animations - here
- Interactive elements - here
- Build a full backend - here
- Go nuts with it - here
- Syntax
- Data Types
- Variables
- Expressions
document.getElementById('header');
document
: object.
: property accessorgetElementById
: property()
: function call'header'
: parameter
Number
looks like: 1 or 500 or 3.14String
looks like "Any Message in Quotes"Boolean
looks like true or falseNull
is an empty value: nullUndefined
is the absence of a value: undefined
Declare a variable
var firstName;
Assign a value to a variable
firstName = 'Tim';
Shorthand (Declare and assign)
var firstName = 'Tim';
- Begin with letters, $ or _
- Only contain letters, numbers, $ and _
- Case sensitive
- No reserved words - here
- camelCase vs using _'s
- Choose and stick with a convention
Variables can store the result of an expression
var age = 2014 - 1983;
var greeting = "My name is Tim and I am " + age + " years old";
var isOld = age > 100;
var firstName = "Tim"; // Single Line Comment
/*
Multi Line
Comment (Comment Block)
*/
var a = 1;
var b = 2;
var c = 1 + 2;
var a = 5 + 5; // 10
var b = a * 2; // 20
var c = 25 / 5; // 5
var d = b - c; // 15
function greet (name) {
return “Hello, “ + name + “!”;
}
greet(“Tim”); // Hello, Tim!