text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
And people often ask, hey, we're on ES6 now.
1,174.33
3.48
There have been six different versions of JavaScript.
1,177.81
2.91
Why don't you just change this to be null?
1,180.72
4.87
And the answer that ECMA gives is, well, the whole internet would break.
1,185.59
4.99
And so each new version of ECMAScript should definitely
1,190.58
4.39
be backwards compatible with the previous versions.
1,194.97
2.37
Otherwise, say I put out a website tomorrow.
1,197.34
3.36
If somebody comes down and changes the JavaScript spec,
1,200.7
2.91
then my website might break.
1,203.61
1.38
And so a lot of websites actually rely on this to be true.
1,204.99
4.26
And, therefore, if a breaking version of ECMAScript is released,
1,209.25
4.47
it might actually just have unforeseen consequences.
1,213.72
2.677
So this is just one of those strange JavaScript gotchas.
1,216.397
2.333
Cool, so another good question would be so when should I use double equals
1,223.62
5.16
versus triple equals?
1,228.78
1.96
And people generally say you should never use double equals,
1,230.74
4.43
because that means you have to know exactly how every single thing coerces.
1,235.17
4.719
And not only you, but every single person who reads your code
1,239.889
2.541
should know what all these values coerce do.
1,242.43
2.97
And some of them might be somewhat surprising.
1,245.4
2.2
So we have a chart here that talks about the JavaScript equality table.
1,247.6
4.43
For those of you who have the slides opened, you can click on that link,
1,252.03
3.01
and it will bring you to the repo that has this.
1,255.04
2.24
Basically, some of these strings are somewhat strange.
1,257.28
3.18
Like how empty array is double equals to false, which doesn't really
1,260.46
7.74
make a ton of sense.
1,268.2
1.432
A lot of these don't really make a ton of sense
1,269.632
1.958
and, basically, never use that double equals because it
1,271.59
3.99
might have some strange behaviors.
1,275.58
1.955
So moving on with coercion.
1,281.156
1.124
So we talked about coercing things into other types,
1,285.22
3.65
but how about if we're getting to bools?
1,288.87
2.22
So JavaScript has these things called falsy values.
1,291.09
3.99
Who can name a falsy value?
1,295.08
3.39
So falsy value is any value that, if cast to bool, becomes false.
1,298.47
6.388
AUDIENCE: Two.
1,304.858
0.912
JORDAN HAYASHI: Two?
1,305.77
1.41
So two is actually truthy.
1,307.18
2.13
So every number except for one number is truthy, well two numbers actually.
1,309.31
4.2
AUDIENCE: Zero.
1,313.51
0.86
JORDAN HAYASHI: Zero would be one of them, yeah.
1,314.37
2.93
Not a number which is actually a number, of type number, is also a falsy value.
1,317.3
6.23
Who can name another falsy value?
1,323.53
2.144
AUDIENCE: Blank?
1,325.674
0.976
JORDAN HAYASHI: Blank what?
1,326.65
0.69
AUDIENCE: Or empty.
1,327.34
0.84
JORDAN HAYASHI: Empty what?
1,328.18
0.69
AUDIENCE: Empty array.
1,328.87
1.282
JORDAN HAYASHI: Empty array is actually truthy.
1,330.152
1.958
False is another one.
1,336.02
2.52
Undefined, null.
1,338.54
1.02
So those are the five falsy values.
1,342.59
2.73
So who can name some truthy values?
1,345.32
1.77
Somebody said two, which is a valid one.
1,349.78
2.39
Three, four, every other number other than zero, negative zero, not a number.
1,352.17
5.98
Empty array is also another truthy.
1,358.15
2.43
Empty object and literally everything else.
1,360.58
3.27
So anything other than those values right there are truthy.
1,363.85
3.75
Cool, so objects, arrays, functions, objects.
1,371.73
3.417
It looks like I put objects twice there, but I actually put it four times.
1,375.147
3.083
So JavaScript has this weird thing where if it's not
1,378.23
3.56
one of those primitive values, it's an object.
1,381.79
1.92
And so we'll talk about this thing in a little bit
1,386.637
2.083
called prototype inheritance, which talks
1,388.72
2.37
about how these objects inherit from each other
1,391.09
2.64
and how they actually work under the hood.
1,393.73
1.83
But first let's compare those two types.
1,395.56
1.89
So we talked about primitives earlier, which is--
1,397.45
2.25
who can name some of the primitives?
1,399.7
3.525
AUDIENCE: Null.
1,403.225
0.895
JORDAN HAYASHI: Null, undefined.
1,404.12
3.24
AUDIENCE: Number.
1,407.36
0.84
JORDAN HAYASHI: Number.
1,408.2
1.394
AUDIENCE: Boolean.
1,409.594
0.916
JORDAN HAYASHI: Boolean.
1,410.51
0.45
AUDIENCE: String.
1,410.96
0.92
JORDAN HAYASHI: String.
1,411.88
0.958
And simple.
1,421.53
0.737
So good, you got them all.
1,422.267
1.083
Nice.
1,423.35
0.5
So everything other than those primitive types are actually objects.
1,428.317
2.833
So primitives are immutable, which means if you
1,431.15
2.577
want to change them, you're actually replacing them with a new value
1,433.727
2.833
rather than actually changing them themselves, whereas objects are not.
1,436.56
4.05
They're actually mutable.
1,440.61
1.92
So who knows what storing by reference means?
1,442.53
4.77
So storing by reference means we actually
1,447.3
2.28
store a reference to this object thing, and we can actually
1,449.58
3.36
change what is held there without actually changing
1,452.94
2.79
where that thing is located in memory.
1,455.73
2.55
We'll talk a little bit more about that in a second.
1,458.28
4.06
But the opposite of that would be storing something
1,462.34
3.23
by a value, which is what happens when you have primitives.
1,465.57
2.76
So, like I said earlier, primitives are immutable,
1,468.33
2.26
which means once you create a primitive, it can't actually be changed.
1,470.59
3.2
And when you want to change something, you actually create a new primitive
1,473.79
3.63
and replace the old one, whereas mutable things are actually
1,477.42
3.51
stored by reference, and you can actually change that object.
1,480.93
3.872
And so let's play with that a little bit.
1,484.802
1.708
So there are a few different ways to create an object.
1,497.68
2.25