Becoming a React-typescript developer series 2:Deep Dive Into Data type in javascript and typescript

Table of contents

No heading

No headings in the article.

when i was first new to programming the word types or Data type was kinda confusing to me then with time i realise that data type are the various kind of values that can be assign to a variable. so today we are going to be looking at the various type or data type we have in javascript and typescript

First, before going deeper into what we have for today let understand the difference between the two

Typescript vs javascript The major difference between these two programming language is that one is dynamically type(javascript) and the other is statically type(Typescript)

Really what is the importance of writing article when some of my readers are confuse or are not able to get along as a result of their lack of experience in the frontend development field . Because of that we will be looking are these two technical word DYNAMICALLY TYPE and STATICALLY TYPE

What is STATICALLY TYPE? it is a term that is use to refer to programming languages that we inform of the type of data type a variable declared in them are allowed to hold or store . example of those programming languages is TYPESCRIPT while dynamically type is the opposite of statically type

shedding more light let assume we declare a variable called name in both javascript and typescript let look at how they behave

//Typescript

let name:string

the expression written above illustrate how variable is declared and how typescript is being informed about the data type they are allowed to hold . starting from the colon(:) section in the expression above down to the end of the expression are the ones that do the job of informing typescript of the data type the name variable is allowed to hold . so any attemting store any other value that are not of the type string typescript will through an error . these is the major concept behind statically typing.

name = "stephen" [will not throw an error]

name = 1 [will throw an error cause a different data type is being assigned to the variable ]

where as

//JAVASCRIPT

let name

but in javascript there is no need of informing it of what data type a variable declared in it is allowed to hold that why these part is missing [:string] during the declaration of the variable name . therefore any data type such as string, boolean,number can be stored in the variable name cause javascript is dynamically type. these is just the major concept behind dynamically type

name = "string" [ error will not be thrown] name = 1 [error will not be thrown]

The various data type availabel in javascript are

  1. Boolean type.
  2. Null type.
  3. Undefined type.
  4. Number type.
  5. BigInt type.
  6. String type.
  7. Symbol type.

Because typescript is an extension of javascript these data type are also available in typescript, but typescript also have data type that are only available to it but are not available to javascript they are listed below

  1. Any & Unknown
  2. Void
  3. Never
  4. Intersection & Union Types