text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
Great question.
1,917.98
0.96
Yeah.
1,918.94
0.681
AUDIENCE: Um-- You cannot do 0.1 for example.
1,919.621
3.768
[INAUDIBLE]
1,923.389
3.301
JORDAN: So, if we did o.1, yeah, so, o.1, 1 here, since we're
1,926.69
5.22
typing it here, is a number.
1,931.91
2.16
And we cannot set keys to numbers.
1,934.07
2.67
But if it were an object literal like this,
1,936.74
2.16
[TYPING]
1,938.9
2.16
JORDAN: It considers this not to be a number, but rather a string.
1,941.06
4.71
AUDIENCE: You can the array assignment by putting brackets around the one
1,945.77
4.95
and passing it as a string, so you can do 0 dot
1,950.72
2.475
[TYPING]
1,953.195
1.485
AUDIENCE: Our brackets around [INAUDIBLE] o
1,954.68
5.692
dot open bracket, open braces, and then, quotes, one.
1,960.372
6.683
And then set that to a value.
1,967.055
4.005
JORDAN: So, I think you mean this?
1,971.06
1.85
[TYPING]
1,972.91
5
Yep.
1,977.91
0.5
And I believe you can also do this.
1,981.362
1.458
[TYPING]
1,982.82
1.62
Because that will get cast to a number.
1,984.44
2.15
I mean a string.
1,986.59
2.79
Any other questions?
1,989.38
3.415
Cool-- yeah?
1,992.795
0.956
AUDIENCE: If you have want the number one inside the bracket notation,
1,993.751
5.757
versus the string one inside the bracket notation,
1,999.508
3.283
it will be treated as the same keys?
2,002.791
1.879
JORDAN: Yeah, so the question is, what is the difference between this here,
2,004.67
3.79
and this here?
2,008.46
1.7
The difference is, anything between the brackets
2,010.16
4.12
will get coerced into a string.
2,014.28
1.99
And so, since this is already a string, it's just that string one.
2,016.27
3.756
Since this is not of type string, it actually
2,020.026
1.874
gets implicitly coerced into a string.
2,021.9
3.04
And so, like we saw earlier, if we did one plus some empty string,
2,024.94
4.16
we get back the string one.
2,029.1
1.59
So this becomes a string one, and it will index into that.
2,030.69
3.06
Whereas, this number here, so if we did o3.1,
2,033.75
3.427
[TYPING]
2,037.177
3.663
That one does not actually get coerced, like it does between the brackets here.
2,040.84
6.3
So JavaScript is basically saying, hey, this doesn't really make sense.
2,047.14
3.99
I need a string here, not a number.
2,051.13
3.7
Cool, any other questions?
2,054.83
1.532
Great-- So, let's talk a little bit about this thing, where
2,063.742
4.897
I was talking about mutating objects.
2,068.639
5.127
So say--
2,073.766
0.499
[TYPING]
2,074.265
3.225
So, say I had this object, so--
2,083.38
2.224
In it we had, a gets a, b gets b.
2,089.54
5.28
So say I wanted to change a to be something else?
2,097.42
3.58
How might I do that?
2,101
1.02
Yes.
2,105.95
0.51
AUDIENCE: dot a equals--
2,106.46
1
JORDAN: Yes, so I can update this to be anything else.
2,107.46
2.46
[TYPING]
2,109.92
3.24
Cool, but say I actually did this.
2,113.16
1.875
[TYPING]
2,115.035
2.715
Anybody care to guess what would be console logged here?
2,128.59
2.84
So basically, what he's doing is, we're creating a new object.
2,133.99
2.72
And storing it in o.
2,136.71
0.96
This object has two keys, a and b, where their values are a and b respectively.
2,137.67
4.41
I'm creating this new object called o2, and assign a value of o.
2,142.08
5.49
I then go reset o.
2,147.57
2.46
Not o2 but o.a to be a new value.
2,150.03
2.67
And I'm going to console log o2.a.
2,152.7
2.88
Anybody care to guess what this is going to console log?
2,155.58
2.59
Yeah.
2,158.17
0.5
AUDIENCE: a?
2,158.67
1.5
JORDAN: So, a guess is a.
2,160.17
1.71
What would be the alternative guess?
2,161.88
2.937
AUDIENCE: New value.
2,164.817
0.833
JORDAN: New value--
2,165.65
2.113
[INAUDIBLE]
2,167.763
1.867
JORDAN: Yeah, so let's run that.
2,169.63
2.27
So you get new value.
2,171.9
0.93
And so I talked about this thing called passing by reference,
2,172.83
2.541
and passing by value.
2,175.371
2.659
So, basically what's happening here, is that o is being said,
2,178.03
6.08
hey, give me a new object, somewhere.
2,184.11
4.14
And then store inside of it, a and b.
2,188.25
2.64
And then o2 says hey, give me another object and set it to o.
2,190.89
4.11
And rather then creating a new object, with the same keys and values,
2,195
3.33
it's actually pointing to that same object.
2,198.33
2.279
So this is a case where things are getting stored
2,200.609
2.041
by reference, rather than by value.
2,202.65
2.15
Meaning, so in CS50, we talked a little bit about pointers,
2,204.8
3.22
and this is the exact same concept.
2,208.02
2.37
Where these objects are not stored as entire serialized objects,
2,210.39
4.96
but rather as references to these objects in memory.
2,215.35
3.53
So o and o2 are both referencing that same exact object.
2,218.88
3.7
So when we go back and say, hey update o.a to be new value,
2,222.58
4.71
it's changing this object here, and still
2,227.29
2.06
o and o2 are both pointing to that same object.
2,229.35
3.43
So if I were to have updated 02 here, and console logged o.a,
2,232.78
6.74
we would get that same result. Because o and o2 are still both referring to that
2,239.52
4.26
same object in memory, and we're still updating that object here.
2,243.78
3.97
Does that make sense?
2,247.75
2.65
Yeah.
2,250.4
0.61
AUDIENCE: So what if you wanted them to be different.
2,251.01
2.208