Disclaimer: This post is a shorten version of What is Javascript made of by Dan Abramov. You can read the full article here.
Value
Primitive Values
Some value types are primitive. They include numbers, strings, and a few other types.
One peculiar thing about primitive values is that you can’t create more of them, or change them in any way.
For example, every time you write 2, you get the same value 2. You can’t “create” another 2 in your program, or make the 2 value “become” 3.
null & undefined
null represents that some value is missing intentionally
undefined represents that a value is missing unintentionally
They exist because sometimes it’s better for an operation to fail than to proceed with a missing value.
Equality
Strict Equality & Referential Equality
We use three equal signs (===) to represent this concept of equality in JavaScript
If two values are equal, it means they are the same value, ACTUALLY. Not two different values, but one!
For example, "Cows go moo" === "Cows go moo" and 2 === 2 because 2 is 2. Note we use three equal signs to represent this concept of equality in JavaScript.
Loose Equality
Loose equality is when we use two equal signs (==).
Things may be considered loosely equal even if they refer to different values that look similar.
This concept is not fundamental, but is a common source of mistakes. You can learn how it works on a rainy day, but many people try to avoid it.
Literal
A literal is when you refer to a value by literally writing it down in your program
For example, 2 is a number literal, and "Banana" is a string literal.
Variable
A variable lets you refer to some value using a name
Thus, you can write message instead of repeating the same sentence every time in your code. For example
let message = "Cows go moo".
You may later change message to point to another value.
message = "I am the walrus"
Note this doesn’t change the value itself, but only where the message points to, like a “wire”. It pointed to "Cows go moo", and now it points to "I am the walrus"
Scope
When you define a variable, it becomes available in a part of your program. That part is called a “scope”.
There are rules about how scope works, but usually you can search for the closest { and } braces around where you define the variable. That “block” of code is its scope.
Assignment
When we write message = "I am the walrus", we change the message variable to point to "I am the walrus" value.
This is called an assignment, writing, or setting the variable.
let vs const vs var
Usually you want let.
If you want to forbid assignment to this variable, you can use const. (Some codebases and coworkers are pedantic and force you to use const when there is only one assignment.)
Avoid var if you can because its scoping rules are confusing.
Object
An object is a special kind of value in JavaScript. The cool thing about objects is that they can have connections to other values.
Disclaimer: This post is a shorten version of What is Javascript made of by Dan Abramov. You can read the full article here.
Value
Primitive Values
primitive
. They includenumbers
,strings
, and a few other types.null & undefined
null
represents that some value is missing intentionallyundefined
represents that a value is missing unintentionallyEquality
Strict Equality & Referential Equality
Loose Equality
Literal
Variable
Scope
Assignment
let vs const vs var
let
.const
. (Some codebases and coworkers are pedantic and force you to use const when there is only one assignment.)var
if you can because its scoping rules are confusing.Object
An object is a special kind of value in JavaScript. The cool thing about objects is that they can have connections to other values.