Javascript - Datatype

Javascript - Datatype

·

5 min read

Hello All, Welcome back to the new feed. Hope You all are Good ! as i am. Today we are Going to learn about datatype in Javascript. Datatype is nothing but type of your data stored in a variable.

DATATYPE

There are Totally Eight Type of Datatype are there in Javascript. They are,

  1. Integer
  2. BigInt
  3. String
  4. Null
  5. NaN
  6. undefined
  7. Objects
  8. Symbols

INTEGER

Integer is nothing but number. In more detail variable the holds the numberic values are integers.It may be a single number or Floating numbers anything i can be. It holds the Special numeric values too, like Infinity.The values will be returned in the type NaN.

We can do any Mathematical Operations in Javascript. Like Addition , Subraction, Multiplication, Division.All these can be done in safe hands. But while working with Special numeric value, it will return NaN without causing any error in script flow.Yes, that is Javascript special.

```let numberOne = 1 let numberTwo = 11.5

// Here the type of both variable is a Integer


### BigInt

We've Saw about Integer in last type right! BigInt is also almost similar and not similar to integer because BigInt is also a numeric values holding type but this hold huger than normal integer.I've Forgot to convey a thing that is,a normal integer can only hold up to a value upto (2^53-1) (that is 9007199254740991). The values that are greater than 2^53-1 will have to be stored in the Big buddy BigInt.

To use BigInt, 

```// the "n" at the end means it's a BigInt
const bigInt = 1234567890123456789012345678901234567890n;

BigInt's are rarely used.Don't Get worry about this.

STRING

After finishing Number's, We've Studied Alphabets in out Kinder Garden.As like that,the next type behind the number is String. String is nothing but a letters or number enclosed in a Double or Single Quotes.It either can be a single letter or a Group of letters normally called as String.

```let nameOne = "Joey" , nameTwo = "Chandler"

// Here the Type of the nameOne and nameTwo are String.

let name = "Chandler Bing" ,nameSplit = "J" ,nameSplitTwo = "O" ,nameSplitThree = "E" ,nameSplitFour = "Y"

above declared all variable are String.

 You can also use Single Quotes create a string,that is mirror to Double quotes.

Above all there is another quote is Js that is Backtick.

Backticks areextended functionality” quotes. They allow us to embed variables and expressions into a string by wrapping them in ${…}, for example:


```let name = "Joey";

// embed a variable
alert( `Hello, ${name}!` ); // Hello, Joey!

// embed an expression
alert( `the result is ${1 + 2}` ); // the result is 3

The expression inside ${…} is evaluated and the result becomes a part of the string. We can put anything in there: a variable like name or an arithmetical expression like 1 + 2 or something more complex.

```alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (double quotes do nothing)


In some languages, there is a special “charactertype for a single character. For example, in the C language and in Java it is calledchar”.

In JavaScript, there is no such type. There’s only one type: string. A string may consist of zero characters (be empty), one character or many of them.


### BOOLEAN 

Have you ever answered TRUE or FALSE questions in your school time.If Yes,That make you so simple to understand Boolean.Because a Boolean is simply True or False. A boolean contains either True or False 

This type is commonly used to store yes/no values: true means “yes, correct”, and false means “no, incorrect”. This is a Logical Type.

let nameFieldChecked = true; // yes, name field is checked let ageFieldChecked = false; // no, age field is not checked

let isGreater = 4 > 1;

alert( isGreater ); // true (the comparison result is "yes")


That's all in Boolean.


### NULL 

The Null is actually nothing.Yes, Null is nothing.The special null value does not belong to any of the types described above.It forms a separate type of its own which contains only the null value:


```let name = null;

In JavaScript, null is not a “reference to a non-existing object” or a “null pointer” like in some other languages.

It’s just a special value which represents “nothing”, “empty” or “value unknown”.

The code above states that name is unknown

UNDEFINED

The special value undefined also stands apart. It makes a type of its own, just like null.

The meaning of undefined is “value is not assigned”.

If a variable is declared, but not assigned, then its value is undefined:

```let name;

alert(name); // shows "undefined"


Technically, it is possible to explicitly assign undefined to a variable:


```let num = 100;

// change the value to undefined
num = undefined;

alert(num); // "undefined"

…But we don’t recommend doing that. Normally, one uses null to assign an “empty” or “unknown” value to a variable, while undefined is reserved as a default initial value for unassigned things.

OBJECT

The object type is special.

All other types are called “primitive” because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities.

Being that important, objects deserve a special treatment. We’ll deal with them later in the chapter Objects, after we learn more about primitives.

SYMBOL

The symbol type is used to create unique identifiers for objects. We have to mention it here for the sake of completeness, but also postpone the details till we know objects.

ps : comment your suggestion on anything that might help my tomorrow with better comeup

Grateful for Your Time