27.4 C
Gujarat
HomeJavascriptData types in javascript

Data types in javascript

six data types that are primitives

     1.undefined 
     2.Boolean
     3.Number
     4.String
     5.BigInt(ECMA morden JavaScript)
     6.Symbol(ECMA morden JavaScript)

1.undefined

The undefined property indicates that a variable has not been assigned a value.

Example:


var abcd;
console.log(abcd);

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
undefined
PS C:UsersThe-BeastDesktopjavascript Blog> 

2.Boolean

In JavaScript Boolean represents true or false.

Exmaple:


var iAmPatel=true;
console.log(iAmPatel)
console.log(typeof(iAmPatel));

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
true
boolean
PS C:UsersThe-BeastDesktopjavascript Blog> 

3.Number

In JavaScript numbers can be written with decimals or without decimals.


Example:

var myAge=22;
console.log(myAge);
console.log(typeof(myAge));

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
22
number
PS C:UsersThe-BeastDesktopjavascript Blog> 

4.String

Strings are useful for holding data that can be represented in text form. A string is used to represent and manipulate a sequence of characters. In JavaScript string characters written inside quotes.

Example:


var myName="patel";
var myname='rocoderes'
console.log(myName);
console.log(myname)
console.log(typeof(myName));
console.log(typeof(myname));

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
patel
rocoderes
string
string
PS C:UsersThe-BeastDesktopjavascript Blog> 

Now challenge time


10 + 20
9  - "5"
"java" + "Script"
" " + " "
" " + 0
"Ro" + "coderes"
true + true
true + false
false + true
false - true

solution:


console.log(10 + 20);
console.log( 9  - "5"); //bug
console.log("java" + "Script");
console.log( " " + " ");
console.log(" " + 0);
console.log("Ro" - "coderes");
console.log(true + true);
console.log(true + false);
console.log(false + true);
console.log(false - true);

output:

In javascript 1 represent is true Or 0 represent is false


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
30        
4
javaScript

 0        
NaN
2 
1 
1 
-1
PS C:UsersThe-BeastDesktopjavascript Blog> 

1.interview question

Difference between null VS undefined?

  • null means empty.
  • when you create a variable but not assign any value. that is undefined

Example:


var iAmUseless=null
console.log(iAmUseless)

var iAmStandBy;
console.log(iAmStandBy)

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
null     
undefined
PS C:UsersThe-BeastDesktopjavascript Blog> 

2.interview question

what is NaN?

  • NaN is a property of the global object.
  • In other words, it is a variable in the global scope.
  • The initial value of NaN is Not-A-Number.

Example:


console.log("Ro" - "coderes");


var myPhoneNumber=9876543210;
var myName="patel";

console.log(isNaN(myPhoneNumber));
console.log(isNaN(myName));

output:


PS C:UsersThe-BeastDesktopjavascript Blog> node index.js        
NaN  
false
true 
PS C:UsersThe-BeastDesktopjavascript Blog> 
RELATED ARTICLES

3 COMMENTS

  1. Hi! Someone in my Myspace group shared this site with us so I came to give it a
    look. I’m definitely loving the information. I’m bookmarking and will
    be tweeting this to my followers! Fantastic blog and outstanding style and design.

  2. My developer is trying to persuade me to move to .net from PHP.

    I have always disliked the idea because of
    the expenses. But he’s tryiong none the less. I’ve been using
    Movable-type on numerous websites for about a year and am anxious about switching to another platform.
    I have heard fantastic things about blogengine.net. Is there a way I can import all
    my wordpress content into it? Any kind of help would be
    greatly appreciated!

  3. Howdy very cool website!! Man .. Excellent ..
    Wonderful .. I will bookmark your web site and take the feeds additionally?
    I’m satisfied to search out so many helpful information right here in the
    publish, we’d like work out more strategies in this regard, thanks
    for sharing. . . . . .

LEAVE A REPLY

Please enter your comment!
Please enter your name here

15,000FansLike
5,000FollowersFollow
535FollowersFollow
- Advertisment -spot_img

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Most Popular