Let's make stuff happen!!!
Mathematical
Access/Assign
Comparison
Logical
Ignore
Other
Keywords
Mathematical
Access/Assign
Comparison
Ignore
Keywords
remember,
don't worry about:
// Mathematical
JavaScript Memory
"I would walk 500 miles..."
"I want to ride my BICYCLE!!!"
9
// Review the slides on numbers if necessary
> 5 + 4; // Self explanatory
> 15 % 4; // Modulus, gets the remainder
// One more thing...
'I want to ride my'
// What about...
'I would walk ' + 500 + ' miles...' //???
3
+ ' BICYCLE!!!'; // ???
String 'concatenation'
For more complex operations, read the docs!
// Comparison (equality)
JavaScript Memory
true
// Are these the same? (in terms of ASCII)
> 1000 === 1000; // ???
> 5000 !== 5000; // ???
// And these...?
> 'Basketball' !== 'and Mr. Curtis Blow'; // ???
> 'Sussudio' === 'Sussudio'; // ???
// What about types?
typeof 'Do the Beat Street Strut!'; // ???
typeof { starlight: 'startbright'}; // ???
typeof 8675309; // ???
typeof function() {}; // ???
false
true
true
"object"
"string"
"number"
"function"
Again, DO NOT use '!=' or '=='
// Assignment and Access
// 'Assignment Operator' (NOT EQUALS!)
> var planet = 'rock!'; // (see variables)
// Arrays [bracket notation only]
['Don\'t', 'stop', 'the', planet][3]; // ???
['do', 'the', 'conga'][3] = 'beat'; // ???
// Objects
> { }['first'] = 'Gloria'; // ???
> { first: 'Gloria' }.last = 'Estefan'; // ???
> { music: 'is gonna get you!' }['music']; // ???
Just a quick intro, more on these later.
JavaScript Memory
"rock!"
"rock!"
{ "first":"Gloria" }
['do', 'the', 'conga', 'beat']
"is gonna get you!"
{ "first":"Gloria", "last":"Estefan" }
Key Takeaways
Remember:
'==' | '!='
'===' | '!=='
Oh wait, I need to use that again
What we'll cover:
// Variable declaration
'Stevie Nicks'
'Edge of Seventeen'
001
002
Slot
JavaScript Memory
// Proper Declaration
> var name = 'Stevie Nicks';
> var song = 'Edge of Seventeen';
// Don't use (for now)
> window.newerName = 'Charlie Parker';
> window.newerSong = 'Early in the Morning';
// NEVER USE
> newName = 'Eddie Money';
> newSong = 'Take me home tonight';
Bad convention: 'new___'
'declaration'
'assigment'
// Rules and Conventions
// Declare and assign at the top of your scope/code
2 > var favBand = 'Earth Wind and Fire';
3 > var favSong = 'Fantasy';
4 >
5 > console.log(favBand, favSong);
// Good Examples (declarations only)
> var songsArray; // Descriptive of the reference
> var artistName; // Single word
> var templeOfTheDog; // 'camelCase': hungryHungryHungry
// Words not to use (your code will break):
// > var new, var, in, function, String, Number, break, typeof...
// Basically, If your editor highlights the word, don't use it!
// Bad Examples (declarations only)
> var SongTitles; // Start with lowercase
> var tracknumber; // Use camelCase
> var newArray; // Of what?
> var &no$yb@ls; // Code will break
Use 'console.log' to check values
// Variable declaration
'David'
'Bowie'
001
002
Slot
JavaScript Memory
> firstNameAgain;
> var firstNameAgain = firstName;
// What is Javascript doing?
> firstName = 001;
> lastName = 002;
// Proper Declaration
> var firstName = 'David';
> var lastName = 'Bowie';
003
'David'
= 003;
// Variable Usage
'StevieWonder'
'Stevie Wonder'
'Stevie'
'Wonder'
// Proper Declaration
> var firstName = 'Stevie';
> var lastName = 'Wonder';
// We want his full Name
> firstName + lastName;
// 'Stevie' + 'Wonder'
// Fix the formatting
> firstName + ' ' + lastName;
// 'Stevie' + ' ' + 'Wonder'
JavaScript Memory
// Variable Usage
'Stevie Wonder'
'Stevie'
'Wonder'
Reference Error
// Proper Declaration
> var firstName = 'Stevie'; // 001
> var lastName = 'Wonder'; // 002
// Print the fullName
console.log(fullName); // ???
// Fix the formatting
> firstName + ' ' + lastName; // 003
// 'Stevie' + ' ' + 'Wonder'
001
002
Slot
003
JavaScript Memory
JavaScript Console
// Variable Usage
'Scott Weiland'
'Scott'
JavaScript Memory
undefined
'Scott Weiland'
'Scott'
JavaScript Console
'Scott Weiland'
Makes a copy for 'primitive' types.
// Declare before using
> var fullName = 'Scott Weiland';
> var firstName = fullName.split(' ')[0];
> console.log(fullName); // ???
> console.log(firstName); // ???
34 // What's gonna happen?
35 > console.log(stoneTemplePilots); // ???
36 > var stoneTemplePilots = fullName; // ???
// Overwriting
> fullName = 'Stone Temple Pilots'; // ???
> console.log(fullName); // ???
'Declared' or 'namespaced' but not 'defined' before it's used. Hence 'undefined'
001
002
Slot
003
// 001
// 002
'Stone Temple Pilots'
004
'Stone Temple Pilots'
// 004
// 003
// 001
// 002
// 004
'Radio'
'Head'
JavaScript Memory
'Radio Head'
JavaScript Console
'Radio Head'
How does the interpreter work?
1 // Top of code scope
2 > var firstName; // undefined
3 > var lastName; // undefined
// skip lines 4 - 53
001
002
Slot
003
54 > lastName => 002 // 'Head'
55 > firstName => 001 // 'Radio'
53 // When we do this:
54 > var firstName = 'Radio';
55 > var lastName = 'Head';
56 > console.log(firstName + ' ' + lastName);
// When we do this:
54 > lastName = 'Head'
55 > firstName = 'Radio'
56 > console.log(lastName + ' ' + firstName);
56 > console.log(001 + ' ' + 002); // ???
56 > console.log(firstName + ' ' + lastName);
Create a 'namespace' and'hoist' anything with the 'var' keyword to the top of the scope
Execute the statement depending on the variables.
Then assign them
// 003
Key Takeaways
What is an 'undefined' variable?
Vocabulary: