Lesson 18
Review of the JavaScript Things We Learned (Part 1)
Summary
Summary of NBK Tech World Lesson
Welcome back to NBK Tech World! This lesson serves as a review of the concepts covered in the course so far. If you're comfortable with the previous lessons, you can skip this video; otherwise, let's continue.
Key Topics Covered
1. Browser Console and JavaScript Commands
- Each major browser has a console (e.g., Firefox) where you can type JavaScript commands.
- The console provides an interpreter that returns results immediately.
2. Printing to Console
- To print a message, you use the
console.log()
method. - Functions perform actions, take inputs, and return outputs. When tied to an object, they're called methods.
3. Variables
- Constants (
const
): Declare a variable that cannot be reassigned.- Example:
const name = 'Your Name';
- Example:
- Let (
let
): Declare a variable that can be reassigned.- Example:
let age = 35;
- Example:
4. Data Types
- Strings: Enclosed in quotes (
'string'
,"string"
,`string`
). - Numbers: Numeric values (e.g.,
35
). - Use
typeof
operator to check types.
5. Mathematical Operations
- Basic math operations (addition, subtraction, multiplication, division) can be performed directly in the console.
- Parentheses can change operation precedence (e.g.,
3 * (4 + 8)
).
6. Special Cases in Math
- Division by zero results in
Infinity
. 0 / 0
results inNaN
(Not a Number).
7. Comparisons
- Strict Equality (
===
): checks both value and type. - Loose Equality (
==
): checks only value, coercing types if necessary. - Comparison operators (e.g.,
<
,>
,<=
,>=
) are also useful. - Strict Inequality (
!==
): checks if two values are not equal in both value and type.
Final Thoughts
Remember to start with const
for variables. Use let
only when reassignment is necessary. The lesson covered fundamental concepts that serve as building blocks for more advanced programming.
This concludes the review. Happy coding!
Video Transcript
Welcome back to NBK Tech World. This lesson will be a review of everything
we've done so far. If you already feel comfortable with all the previous lessons
you can skip this video. Otherwise let's keep on going. So going back to the
beginning of the course we learned that every major browser contains a browser
console and in my case right now I'm using Firefox we can open up the
console and we can type JavaScript commands here and we have an interpreter
that will give you the result on the spot. So the first thing we learned how
was how to print a message to the console. We learned about the console object
that has a method and that method is called log. So remember when we have
functions functions do something they take some input they do some processing
and they return give you back some output that's the general idea of functions.
Now we learned also that when we have a function and when that function belongs
to an object in this case the console object we can call that function a
special name called method. So you might hear the terms function and method used
interchangeably but there's that slight difference. So if the function is by
itself and it's not tied to any object it is not really a method but if it is
tied to some object you can call a method. Anyways let's keep on going let's do
the review. So essentially the function will take an argument which is kind of
the input so you have to tell it what to print to the screen. We can just print
any message we want using a string. A string is a set of characters enclosed by
quotes. By convention I'm using the single quotes convention but mind you
there are other types of quotes like the double quote and the back ticks and they
all have slightly different behavior we haven't really learned in detail about
those but just keep in mind anything under quotes think about strings okay. So the
function will produce this print out to the console with whatever you gave as a
string here. So in this case we got hello world. Alright so that's how we
started then we learned about the concept of variables to store information. So we
can define or declare a variable and then define it with a value in two ways
and the first way is with a const keyword. We can define for example a variable
called name and to that let's assign a string to it. Let's call it whatever
your name is. I will just call it my name. Right we learned that this string will
be stored in this variable called name and because we use const that value can
only be assigned once. So if I try to change name like this some other name
we're gonna get an error because in violet assignment to const and that's
because the const if you define declare variable const it will only allow you to
assign a value once. If you want to be able to change the value of the variable
name again like I tried to do here you have to use another keyword and that's
the keyword let. So if you say let for example let's create another variable
called age. I'm gonna give an arbitrary number okay. So let age be 35 so the
variable age contains the value 35 which by the way is what kind of type in
JavaScript that's a number okay. It's not within quotes it's just a number by
itself so it's type of number okay. Remember type of operator you can type
type of and putting whatever you want to find out the type of and it gives you a
number. So we also learned that right. So going back to the let if I try to change
age to something else like 23 notice that now it works there's no error like
before and if I see what's inside age it's exactly 23 the new value. So that's
because we use the word let. So if you want to change be able to change assign
the value to the variable age more than once not just the first time like we did
here you use let. My advice is to always start out with cost and if later as you
program and do more add more code if you feel that's necessary for the variable
to be changed you should change the cost to let in the declaration. Alright so
that's it for variables and then we talked about the numbers and operations
on the numbers basic math that kind of stuff. So I'll be pretty quick with that
I think you got the point we can do mathematics here right on the console
23 minus 11 gives you 12 and 20 divided by 5 gives you 4 7 times 3 21 and you
can do addition 9 plus 2 11 right. We learned about parentheses if you have
3 times 4 plus 8 but if you do it like this because of the precedence of the
operators the 3 will multiply 4 first if we actually intended for the 4 to be
added to 8 first you would have to add the parentheses right. That's where you're
forcing the addition to be the first thing they'll be 12 and then you do 3
times 12 which is 36. If you didn't have that right you're going to get something
else because the multiplication always takes precedence over addition. So we
get 12 plus 8 which is 20 totally different value right. We also learned
about some things like if you try to divide by 0 what do you get you're gonna
get infinity if you take a number that's non-zero and divide by 0 but if you take
0 and divide by 0 you get NAN which means not a number okay this is not a
number. So if you just type off let's see what we get. So 0 divided by 0 wow it's
type number okay all right so whoops I accidentally open the other window that
continue your type of to find out what the type of this guy is you can see is
also a number so both these guys seem to be a number okay so
you have hello well and if you have a number within strings
it's actually strings not really a number so we learn also about that because
3 is not really equal to 3 if you use the triple equals operator right because the
triple equals the strict equality it compares not only the contents but also
the type of each operand operand is whatever is next to the operator here so in this case
the slap hand side operand 3 so 3 this is a number there's no quotes and on the right hand side
there's a number but it's within quotes so this guy must be a string but a string is not really
a number so this guy is strict equality saying it'll be false but if you have double equal
equals that's not so strict so it's actually going to give you what is 3 equal to the string 3
it's going to be true because it only compares the contents it tries takes this guy okay let's
try to make it a number because you have a number of things strings so it tries to convert
to a number and it succeeds because it's just a number under quotes and it's actually
equal in content even though the type is different we have a number on the left hand side we have a
string on the right hand side so we learned that about those kind of comparisons and can use other
kinds of operators uh greater than greater than or equal to less than less than or equal to we also
learned about the strict inequality right which is the opposite of the triple equal sign if you
want to check if something is not equal to another thing in a strict fashion okay
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: