text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
We'll talk about that
a little more later. | 478.51 | 1.749 |
But for now, we'll just use
this keyword called const. | 480.259 | 2.402 |
So if I want to declare a
variable, I'd say const. | 482.661 | 2.189 |
So give me a variable called first name. | 484.85 | 1.76 |
And I can give it any value I want. | 491.89 | 2.55 |
So let's just call it my first name. | 494.44 | 1.66 |
So you notice I have a
string literal there. | 499.4 | 1.89 |
It's using double quotes, and then I
end that statement with a semi-colon. | 501.29 | 6.24 |
I can also do a last name. | 507.53 | 1.2 |
And if you notice, this time, I
still have that string literal, | 513.736 | 2.624 |
but this time I'm using single quotes. | 516.36 | 1.439 |
Because in JavaScript
there's really no difference | 517.799 | 2.083 |
between double and single quotes. | 519.882 | 1.398 |
You also notice I omitted that
semi-colon, which in JavaScript is OK. | 521.28 | 3.72 |
So my colons are actually optional. | 525 | 1.47 |
So say I wanted something
that was not a string. | 529.44 | 2.88 |
I can just give it a value, like 42. | 532.32 | 3.63 |
So in C, you might see
something like, give me an int, | 535.95 | 3.63 |
or give me a string or a char star. | 539.58 | 4.622 |
You're declaring types
right away with C, | 544.202 | 1.708 |
but for something like JavaScript,
you actually don't have to do that. | 545.91 | 4.78 |
We can also do arrays. | 550.69 | 1.31 |
And we can just declare them in
line like this, and I can have-- | 554.654 | 2.666 |
So, if you notice, I actually have
three different types all in this array. | 574.73 | 3.72 |
So I have a string, I have a
number, and I have a function. | 578.45 | 2.825 |
And this is perfectly fine. | 581.275 | 1.125 |
JavaScript doesn't really care
what you throw in an array. | 582.4 | 2.416 |
You can have all sorts of
different variable types. | 584.816 | 3.184 |
And so say we want to access
those things in an array. | 588 | 2.597 |
Anybody care to guess
exactly how I would do that? | 590.597 | 2.083 |
So say I want to execute that function. | 592.68 | 2.32 |
How might I go about doing that? | 595 | 1.62 |
Any guesses? | 596.62 | 1.54 |
Yeah. | 598.16 | 1.567 |
Yeah, exactly. | 599.727 | 0.583 |
The array of two. | 600.31 | 0.708 |
So if you're familiar with
other languages, a lot of them | 601.018 | 2.592 |
have the same syntax for
indexing into an array. | 603.61 | 2.57 |
And so since we have three
things in this array, | 606.18 | 2.71 |
we do what's called zero indexing,
whereby the first index in that array | 608.89 | 3.54 |
is called the zeroth index. | 612.43 | 1.65 |
And then you count from there. | 614.08 | 1.41 |
So we have zeroth here,
first, and second here. | 615.49 | 3.22 |
And so say I want to
access that function. | 618.71 | 2.09 |
I just do array 2, and
I get that function. | 620.8 | 2.94 |
And say I now wanted to
execute that function. | 623.74 | 2.43 |
I can, say, execute it like that. | 626.17 | 1.742 |
So this is something that you
might see in other languages, | 627.912 | 2.458 |
but JavaScript you can do it as well. | 630.37 | 1.86 |
You can just grab that function out of
that array and execute it like that. | 632.23 | 5.66 |
Say I wanted a for loop, and I wanted
to console log everything in that array. | 637.89 | 3.25 |
I can do it just almost
like C. So I can do for-- | 641.14 | 5.7 |
this time we'll use
let for the variable. | 646.84 | 2.13 |
We'll talk a little
more about that later. | 648.97 | 2.09 |
So I start at zero. | 651.06 | 1.327 |
Well i is less than the raised length. | 652.387 | 1.583 |
[TYPING] | 653.97 | 2.43 |
You might see me-- | 668.08 | 0.9 |
my personal preference is
to omit the semicolons, | 668.98 | 2.85 |
but you might read something
online that has them. | 671.83 | 2.46 |
It really doesn't matter all that much. | 674.29 | 2.12 |
And so this line of code here. | 676.41 | 1.25 |
You might have seen a for loop in
other languages that you've used. | 677.66 | 2.54 |
So this one is just saying
for give me a variable that's | 680.2 | 2.58 |
called i that starts at zero. | 682.78 | 1.92 |
And while it's less than the
number of values in the array-- | 684.7 | 2.97 |
array.length-- just
keep incrementing it. | 687.67 | 2.13 |
And then every single
time console.log, which | 689.8 | 2.85 |
is JavaScript's print function,
whatever that value in that array is. | 692.65 | 5.07 |
So we can actually run this. | 697.72 | 1.23 |
And as you see the first
time, line 12, where | 702.92 | 8.36 |
we say index into that array to
the second value, and call it. | 711.28 | 4.74 |
That's what's printing high. | 716.02 | 1.47 |
And this for loop here will now
print string 42 and this thing called | 717.49 | 3.18 |
function, which is this function. | 720.67 | 3.23 |
Cool, any questions on syntax? | 723.9 | 2.32 |
Yeah. | 726.22 | 0.6 |
AUDIENCE: In your array
there, does it matter if you | 726.82 | 3.08 |
have that third comma after your-- | 729.9 | 1.66 |
JORDAN HAYASHI: It does not matter. | 731.56 | 1.458 |
So the question was, does it matter on
line 9 that comment at the very end? | 733.018 | 4.292 |
And so JavaScript allows you to have
trailing commas, meaning in arrays, | 737.31 | 3.46 |
objects, or even function calls. | 740.77 | 1.742 |
You can actually have extra commas, and
it doesn't matter whether you have it | 742.512 | 3.208 |
or not. | 745.72 | 0.63 |
It's optional just
like the semicolon is. | 746.35 | 2.37 |
But were I to omit
the comma here and try | 748.72 | 2.94 |
to run that, I'm going to get
a syntax error as expected. | 751.66 | 4.86 |
Cool, any other questions? | 760.2 | 3.134 |
Great. | 763.334 | 1.476 |
So back to slides. | 764.81 | 0.75 |
So types. | 765.56 | 0.594 |
So we talked about types
a little bit earlier, | 766.154 | 1.916 |
and I'm just going to talk a
little bit more about them. | 768.07 | 2.68 |
So JavaScript has what's called dynamic
typing, meaning given a variable, | 770.75 | 4.13 |
it has no type associated with it. | 774.88 | 2.05 |
So just like I said, give me
a variable called first name | 776.93 | 3.59 |
and set it equal to a string. | 780.52 | 1.92 |
I could actually change
that later to, say, a type | 782.44 | 2.46 |
number or a Boolean
or anything like that. | 784.9 | 2.22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.