A compuer program can simply be explained as a piece of code that manipulates something.
So what is something?
Let’s ask the computer to perform some task,
Hey, computer print “Hello Devs” 2 times.
So, in the above statement, there are two entities,
- “Hello Devs”
These will be the values used by the computer program.
First is a set of characters and the second is digit/number these are called types.
Ok, what if we want these values later in our program?
Let’s save values in some container and name that container as abc.
This container is called a variable.
- Primitive types
- Object type
Primitive types include numbers, strings of text, and boolean values(true/false).
The special type of values like null and undefined are primitive values, but they are not numbers, strings, or boolean.
ES6 added a new special-purpose type, known as Symbol.
Any value that is not a primitive value(number, string, boolean, symbol, null, or undefined) is an Object.
An object is a collection of properties where each property has a name and value pair.
The values of an object can be a primitive value or another object.
The number is used to represent integers.
This means it can represent numbers as large as +/- 1.7976931348623157*10^308 and as small as +/- 5*10^-324.
If we use integer values larger than the range, we may lose precision in trailing digits.
I will explain Numbers in detail in an upcoming article.
A String is an immutable ordered sequence of 16-bit values. Each 16-bit value represents a Unicode character.
The length is the number of 16-bit values that are used to represent a string.
null is a reserved keyword to represent the absence of the value.
Using typeof operator on null returns type as an “object”, indicating that null can be used as a special value that indicates “no object”.
The undefined value represents a deeper kind of absence. It is the value of the variable that not has been initialized.
Many times we see this value when we try to get the value of an object property or array element which does not exist.
undefined is a predefined global constant(not language keyword as null) that is initialized to an undefined value.
If we try to apply typeof operator to an undefined value it returns “undefined”, indicating that this is a member of a special type.
Symbols were introduced in ES6 to use non-string property names.
Before ES6 property names are typically a string.
To obtain symbol values, we need to call the Symbol() function.
This function never returns the same value twice even we call it with the same argument.
This method allows us to create the same symbol value twice.
Passing the same string argument to Symbol.for() method returns the same symbol value.
Symbol.keyFor() returns the string that we passed as an argument to Symbol.for().
let var1 = Symbol.for(“test”); let var2 = Symbol.for(“test”); va1 === var2 // true
In the programming language, we use names/identifiers to represent values.
Binding name to value gives us a way to refer to that value ad use it in the programs we write.
By doing this we can say that we are assigning value to a variable.
The term variable implies that a new value can be assigned: the value associated with the variable may vary as our program runs.
If we permanently assign some value to a name, that name we refer to as constant instead of variable.
The scope of a variable is the region of our program source code in which it is defined.
Variable and constant declared with let and const are blocked scope. This means the variable is only accessible inside the code block where let or const exists.
If we declare the global variable using the var keyword it is a part of the global object and can be referred to as globalThis.
Global declared with var can not be deleted using the delete keyword.
Variable declared with let and const are not a part of globalThis.
In the next article from this series, I will cover the Number data type in detail.
Hope you like it, if yes **like & share.**
Thanks for your time.