Immutables (not chageables)
// Primitive Data Types
String // 'Javascript is awesome!', "Really awesome!"
Number // 4, 150, 2345, 4.5
Boolean // true, false, -1, 0, 1,
null // "defined" as no value
undefined // not yet defined
The data type for plain language
// Javascript Strings
// RULE 1: Must be between balanced quotes
typeof 'Javascript is awesome!'; // 'string'
// RULE 2: Escape special characters
'Can\'t beat Javascript so don\'t try';
// RULE 3: Can have numbers, symbols, ANYTHING
'Jenny\'s #: ($%@)867-5309';
// Javascript Strings
// Indexed, starting at 0
'Dancing in the street'[0]; // "D"
0123456789...
// Immutable
'I hear, the secrets that...'
0123456789...
// Iterable (can loop through)
for (var index = 0; index < 9; index++) {
console.log('JScript'[index]);
}
// "J", "S", "c", "r", "i", "p", "t"
[2] = 'f';
// NOPE!!!
Key Takeaways
Instructions:
"Coding tiiiime"
Let's code!!!
Just do all the stuff you do with numbers...
// Javascript Numbers
// Numbers are numbers
13, 2357, 5634634564356456
// Decimals too
45.33466362363
JavaScript Memory
563463456...
2357
45.3346636...
13
// Javascript Numbers
// Mathmatical operations
> 21 + 7: // ???
> 3.14 + 5: // ???
> 3 * 5; // ???
> 15 / 3 // ???
> 15 % 9; // ???
JavaScript Memory
3 * 5
3.14 + 5
15 / 3
21 + 7
15 % 9
// Javascript Numbers
// Mathmatical operations
> 21 + 7: // ???
> 3.14 + 5: // ???
> 3 * 5; // ???
> 15 / 3 // ???
> 15 % 9; // ???
JavaScript Memory
15
8.4
5
28
6
// Javascript Numbers' "METHODS"
// Is this a number?
typeof 523454 // ???
// 'STRINGIFY' this number
55.00.toString(); // ???
77.toString(); // ???
(99).toString(); // ???
// Numberify a 'STRINGIFIED'
Number('453'); // ???
JavaScript Memory
ERROR
55
"99"
"number"
453
// Javascript Numbers Methods
// When adding numbers
600 + '400'; // ???
// When using some methods
54.435345.toFixed(2); // ???
// Combining methods and operations
10 + 54.435.toFixed(2); // ???
// Just to be safe???
Number(10 + 54.435.toFixed(2)); // ???
JavaScript Memory
"1054.44"
"54.44"
Try it!
"600400"
Be Careful and pay attention to detail!
JavaScript Memory
64.44
54.441
1054.44
// Javascript Numbers Methods
// What's this???
Number(10 + 54.435.toFixed(2));
Be Careful and pay attention to detail!
// And what about this?
Number(54.435.toFixed(2) + 10);
// And this?
Number(54.435345.toFixed(2)) + 10;
// Javascript Numbers Methods
Key Takeaways
Let's code!!!
[Add link to exercises here and/if directions]
[Anything else?]:
new pairs?
how long?
Resources?
True, False | Truthy <> Falsy
True, False | Truthy <> Falsy
// True
// Absolute truth
> 4 === 4; // true
> 4 !== 5; // True
> typeof 'BBoys make some noise...' === "string"; // true
// Relative truth
> if ('Moose rocks dance floors') console.log(true);
// Write a function that returns true if Moose rocks dance floors
> (function() { })()
var indeed = false;
if ('Moose rocks dance floors') indeed = true;
console.log(indeed);
// Create function that explains the 5 goat rappers
> (function() {
var isTheGoat = false;
// Google it!
var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
// Check if the 'goat' is the correct answer
if (goat === 'DYLAN') {
// Is the goat?
isTheGoat = true;
// if correct, tell us who
for (var i = 0; i < 5; i++) {alert(goat + '!')};
// Then tell us why
setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
// Break out of the function and tell us the truth
return isTheGoat; // OPTIONAL
}
return isTheGoat;
})();
// Absolute equivalence
// Is 4 equal to 4
> 4 === 4; // true
// Is 4 not equal to 5
> 4 !== 5; // true
// Is 4 greater than 5
> 4 > 5; // false
// Is this the correct data type
> typeof 'BBoys make some noise...' === "string"; // true
> typeof 'Love is a battlefield!' === "number"; // false
// Absolute Equivilence
JavaScript Memory
false
true
true
// Is 4 equal to 4
> 4 === 4; // ???
// Is 4 not equal to 5
> 4 !== 5; // ???
// Is 4 greater than 5
> 4 > 5; // ???
// True
// Absolute truth
> 4 === 4; // true
> 4 !== 5; // True
> typeof 'BBoys make some noise...' === "string"; // true
// Relative truth
> if ('Moose rocks dance floors') console.log(true);
// Write a function that returns true if Moose rocks dance floors
> (function() { })()
var indeed = false;
if ('Moose rocks dance floors') indeed = true;
console.log(indeed);
// Create function that explains the 5 goat rappers
> (function() {
var isTheGoat = false;
// Google it!
var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
// Check if the 'goat' is the correct answer
if (goat === 'DYLAN') {
// Is the goat?
isTheGoat = true;
// if correct, tell us who
for (var i = 0; i < 5; i++) {alert(goat + '!')};
// Then tell us why
setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
// Break out of the function and tell us the truth
return isTheGoat; // OPTIONAL
}
return isTheGoat;
})();
// Absolute equivalence
// Is 4 equal to 4
> 4 === 4; // true
// Is 4 not equal to 5
> 4 !== 5; // true
// Is 4 greater than 5
> 4 > 5; // false
// Is this the correct data type
> typeof 'BBoys make some noise...' === "string"; // true
> typeof 'Love is a battlefield!' === "number"; // false
// Absolute Equivilence
JavaScript Memory
false
false
true
// Is this the correct data type
> typeof 'B, BBoys and [B]Girls' === "string";
// Is this the correct data type
> typeof 'Love is a battlefield!' === "function";
// Is this the correct data type
> typeof function letsDance() {} === "number";
// True
// Absolute truth
> 4 === 4; // true
> 4 !== 5; // True
> typeof 'BBoys make some noise...' === "string"; // true
// Relative truth
> if ('Moose rocks dance floors') console.log(true);
// Write a function that returns true if Moose rocks dance floors
> (function() { })()
var indeed = false;
if ('Moose rocks dance floors') indeed = true;
console.log(indeed);
// Create function that explains the 5 goat rappers
> (function() {
var isTheGoat = false;
// Google it!
var goat = prompt("Who are the 5 goat rappers?").toUpperCase();
// Check if the 'goat' is the correct answer
if (goat === 'DYLAN') {
// Is the goat?
isTheGoat = true;
// if correct, tell us who
for (var i = 0; i < 5; i++) {alert(goat + '!')};
// Then tell us why
setTimeout(function() {alert('BECAUSE I SPIT HOT FIRE!')}, 2000);
// Break out of the function and tell us the truth
return isTheGoat; // OPTIONAL
}
return isTheGoat;
})();
// Relative Equivilence
JavaScript Memory
false
false
true
// Does Moose rock dance floors
> if ('Moose rocks dance floors') {
console.log(true);
} // ???
// Is this the correct data type
> typeof 'Love is a battlefield!' === "function";
// Is this the correct data type
> typeof function letsDance() {} === "number";