By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
Responding to and Tracking Key Presses
How to Work With Responding to and Tracking Key Presses
JavaScript
Passing a JavaScript Value Between HTML Pages
Passing a JavaScript Value Between HTML Pages
JavaScript
Compare Objects in an Array
JavaScript Problem: Compare Objects in an Array
JavaScript
Switching Name Order Using Capturing Groups in Regular Expressions
Switching Name Order Using Capturing Groups in Regular Expressions
JavaScript
Shuffling an Array
JavaScript Problem: How to Perform Shuffling an Array
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > What are Data Types in JavaScript? With Example
JavaScript

What are Data Types in JavaScript? With Example

Admin
Last updated: 2022/11/24 at 4:38 AM
Admin
Share
3 Min Read
data types in javascript
Data Types in JavaScript

In this article, we will see some basic data types in JavaScript with some examples.

Contents
Basic Data Types in JavaScript1.undefined2.Boolean3.Number4.StringNow challenge timesolution:

Six data types that are primitives

     1.undefined 

     2.Boolean

     3.Number

     4.String

     5.BigInt(ECMA morden JavaScript)

     6.Symbol(ECMA morden JavaScript)

Basic Data Types in 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

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

TAGGED: data types in javascript
Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Posted by Admin
Follow:
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
Previous Article variables and values in javascript What are Variables And Values in JavaScript
Next Article Dictionary app How to Make A Dictionary app using JavaScript
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

Responding to and Tracking Key Presses

How to Work With Responding to and Tracking Key Presses

February 5, 2023
Passing a JavaScript Value Between HTML Pages

Passing a JavaScript Value Between HTML Pages

February 3, 2023
Compare Objects in an Array

JavaScript Problem: Compare Objects in an Array

January 30, 2023
Switching Name Order Using Capturing Groups in Regular Expressions

Switching Name Order Using Capturing Groups in Regular Expressions

January 29, 2023
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?