Js Free Notes by DP 3
Js Free Notes by DP 3
Courses ×
Podcast
Web Development
×
About me
×
Blog ×
🔥 Beginner
Tips
real spicy
×
JavaScript Notes
× Speaking × /uses ×
Contact
Variables and
Statements
Enjoy these notes? Want to Slam Dunk JavaScript?
These are notes based on my Beginner JavaScript Video Course. It's a fun,
exercise heavy approach to learning Modern JavaScript from scratch.
BeginnerJavaScript.com
Use the HTML base snippet and add a script tag within the
body.
1. var
2. let
3. const
var
Let's start with var .
To make a variable you type var and then you make a name of
the variable. You can use almost anything for a variable name
(we will discuss the restrictions shortly).
<body>
<script>
var first = 'wes';
console.log(first);
</script>
</body>
let
The second way to declare a variable is with let .
const
The third way is with const . Below the age variable, add the
following: 👇
When you are done writing your statement, you add a semi-
colon to the end of the line.
Code Blocks
One thing that we will run into in JavaScript is something
called a code block.
You should see the message "you are old" in the console.
Code blocks are things that are bound by these curly brackets
{ and } .
<script>
var first = "wes";
let age = 300;
const cool = true;
</script>
first = 'westerhoff';
For example type in the console age = 400 . That updates the
value of the age variable.
What we need to know right now is just that var and let
variables can be changed or updated, and const variables
cannot.
Strict Mode
The next thing you need to know about variables is this thing
called Strict Mode.
<script>
// var first = 'wes';
// let age = 300;
// const cool = true;
// first = 'westerhoff';
// cool = false;
dog = "snickers";
</script>
That leads to bad code down the road, it's pretty sloppy and
it's not something that you want to do. So what happened?
var dog;
dog = "snickers";
Scoping
Now let's talk about the second difference between var , let ,
and const , which is scoping.
You may sometimes see people say var variables are old or
deprecated, but they are not.
Naming Conventions
Last thing we need to talk about is naming conventions.
For example you could create the variable below and it would
work. A variable like $_$ would also work.
$ and _ are the only non a-Z characters that can be used at
the start of a variable name.
Camel Casing
Sometimes a variable is made up of two words, for example 👇
const iLovePizza;
Snake Case
There is also something called snake case.
// camel case
const iLovePizza = true;
// UpperCamelCase
const ILoveToEatHotDogs = false;
// snake case
const this_is_snake_case = "cool";
Find an issue with this post? Think you could clarify, update or add
something?
All my posts are available to edit on Github. Any fix, little or small, is
appreciated!
Edit on Github
← Prev Next →
Listen Now →