Store Of Values in Javascript

Sanjib Roy
4 min readMar 2, 2020

--

This is my first article on Javascript. In this article, I’ll discuss some basics of Javascript. There are mainly four things we need to know to learn any language -

  1. Store Of Value.
  2. Store Of Action.
  3. Conditions.
  4. Loops.

In this article, we will discuss the store of values. Let’s break the sentence “Store Of Value”. There are two things we need to know here first is what are the values we can store and second is how can we store those values. So let’s begin with values and understand what are the values that we can access or store in Javascript.

A. Values:

In Javascript, there are 8 types of values. These types of values are also known as “Data Types”. So the 8 Data types are —

  1. Number: The number type represents both integers and floating-point numbers. In Javascript, the limit of integers is (±2)⁵³. We can get the largest integer value by using the static method of Numbers which is Number.MAX_SAFE_INTEGER (9007199254740991 ~ 9 quadrillion).

a. Infinity: It represents Infinite values.

console.log(100 / 0); // Output : Infinity

b. NaN: NaN stands for “Not a Number”. Basically it represents computational errors. Suppose you are dividing alphabet “A” by 2 which is not possible then it results in NaN.

console.log("A"/2); // Output: NaN

2. BigInt: It represents integer values larger than +²⁵³ or lesser than -²⁵³. This type was recently added to the Javascript.

3. String: String is a sequence of characters. characters can be anything numbers, alphabets, symbols, etc. In Javascript string must be enclosed in single quotes(‘ ’), double quotes (“ ”) or backticks (``).

let sayHello = "Hello";
console.log(sayHello); // Output: "Hello"
let sayHi = 'Hi';
console.log(sayHi); // Output: "Hi"
let name = "Reettik";
console.log(`Hello, ${name}`); // Output: "Hello, Reettik"

4. Boolean: Boolean has two values true and false. Boolean values come as a result of the comparison.

console.log(5 > 2); // Output: true
console.log(10 < 5); // Output: false

5. null: null is a special type of value that represents nothing, empty or value unknown. In Javascript, it does not represent a reference to a non-existing object or null pointer like other programming languages. You can consider it as a bug that typeof null is “object”. Actually null type has exactly one value that is “null”. Click here for detailed information.

6. undefined: undefined type also has exactly one value that is undefined. It represents that value is not assigned or function did not return anything etc.

let a;
console.log(a); // Output: undefined

7. Symbol: Symbol is a non-string datatype that can be used as the key of an object. To create a symbol use Symbol(“optional string”) and each time it creates a new symbol even with the same string.

let newSymbol = Symbol();
console.log(typeof newSymbol); // Output: "symbol"
let newSymbol1 = Symbol("abc");
console.log(typeof newSymbol1); // Output: "symbol"
let newSymbol2 = Symbol("abc");
console.log(typeof newSymbol2); // Output: "symbol"
console.log(newSymbol1 === newSymbol2); // Output: false

8. Object: All the above data types are primitive data types means they can store only value but an object is a non-primitive data type. An Object can hold a collection of key-value pairs. We can access these values in two ways —

i. ObjectName.key;

ii. ObjectName[“key”];

*If the key name is stored inside a variable then we have to use the second way to get the value because it does pre-computation. So it’ll replace the variable name with the key stored inside the variable and then access the value of that particular key. In this case, the syntax will be —

ObjectName[variable];

let studentObject = {
name : Suvodip Gorai,
roll : 1,
class: 12
};
console.log(studentObject.name); // Output: Suvodip Gorai
console.log(studentObject["roll"]); // Output: 1

B. How can we store values?

To store anything the first thing we need is a container. In Javascript, there is a container called “variable” where we can store values. We have already discussed that only Boolean, number, BigInt, string, object, symbol, null, undefined will be considered as a value anything except these eight is not a value.

First, we have to create a container and give it a name so that we can easily find it. After that, we can put things into it.

Similarly to use the variable we have to declare it. After that, we can assign value to it. Assigning value in a variable is called variable initialization. Variables are declared with the var, let and const keyword.

Syntax:
let variableName;
var variableName;
const variableName;

Variables declared with const keyword stores only the constant values we can’t reassign or modify those variables. Unlike const, we can modify variables declared with let or var keyword. Although let and var do the same task but there are some differences between them and we will discuss it later.

So that’s it for now. I hope I’ve cleared all your doubts regarding this topic. See you soon in the next blog.

--

--