📒
SDV503
  • SDV503
  • Command Prompt
    • Windows Command Prompt
    • Mac OS Terminal
  • GIT & GITHub
    • GitHub
    • Git
      • Git Workflow
        • Forking Workflow
  • README
    • How to write a readme.md file?
    • Write a better README.me
    • Generate a README for GitHub Repo Quickly
  • Code-comments
    • Clean Comments
    • Writing Comments in a Good way
  • Pair Coding
    • What is Pair Coding?
    • Pair Programming Experience
  • Programming?
    • What is Programming?
    • What Is A Programming Paradigm?
    • JavaScript Programming Paradigms
  • Number Systems
    • Decimal and Binary numbers
  • JavaSCript
    • Introduction To JavaScript
      • The JavaScript Engine
  • JS Call Stack
    • JavaScript call stack
    • JavaScript & Memory
      • Memory Leaks in JavaScript
    • Execution Context and Execution Stack in Javascript
      • Javascript Execution Context and Hoisting
  • JavaScript Variables
    • Introduction to JS Data Types
    • Primitive and Non-Primitive
    • Operator precedence and associativity
      • JS Operators Part One
      • JS Operators Part Two
      • JS Operators Part Three
    • Clean Code for JS Variables
  • JavaScript Scopes
    • Scope (Chain) Visualized
  • Javascript  — this keyword
  • JavaScript Data Types
    • More JavaScript Data Types
  • JavaScript Expressions and Statements
  • if/else, switch and ternary operator
    • If/Else statement
  • Switch Statement
  • Ternary Operator
  • JavaScript Loops
    • Loops in JavaScript
      • Trouble With Loops
  • Objects
    • JavaScript Objects
      • Prototypal Inheritance Visualized
      • JavaScript Number Object
      • JavaScript String Object
  • Functions
    • JavaScript Function Part One
    • JavaScript Function Part Two
    • Immediately Invoked Function Expressions ~ IIFE
    • JS => Arrow Functions
    • JavaScript Callback
    • Hoisting in JavaScript
      • Hoisting Visualized
    • Recursion Functions
    • Curry and Function Composition
  • JavaScript Features
    • JSpread Operator
    • JavaScript Built-in Functions & Objects
  • Data Structures&Algorithms
    • JavaScript’s Data Types
    • Data Structures in JavaScript
      • Introduction to Big O Notation
      • Big O Notation in Javascript
      • Linked Lists
        • Linked Lists — 2
      • Hash Tables
      • Stack & Queue
  • TLDR
    • Single quotes (‘ ’) and double quotes (“ ”) in JavaScript
  • ES6
    • Generators and Iterators
    • Javascript Classes
    • JavaScript closures
    • JavaScript Promises & Async/Await
      • Event Loop Visualized
  • C#
    • What does C#? (C Sharp)
    • C# vs JavaScript
    • What Is The Difference Between C#, .NET, ASP.NET, Microsoft.NET, and Visual Studio?
    • What is the .NET Framework?
    • Methods and Properties of Console Class in C#
    • Datatypes in C#
    • C# Code Comments
    • The if statement
    • The switch statement
    • Loops
    • Comparison operators
    • Addition assignment operators
    • The String Interpolation Operator
    • Arrays
    • Lists
    • Dictionaries
Powered by GitBook
On this page
  • 1. Number
  • 2. String
  • 3. Boolean
  • 4. Null
  • 5. Undefined
  • 6. Object
  • 7. Symbol
  • typeof Operator

Was this helpful?

  1. JavaScript Variables

Introduction to JS Data Types

For a computer everything is 0s and 1s. A computer does not know the difference between “1234”, “QWERTY”. In a programming language all the general and common values we use are classified and organized. This distribution of values in a particular pattern can be called a Data Type. There are seven DataTypes. They are:

1. Number
2. String
3. Boolean                  [ BUNSONS ]      
4. null
5. undefined
6. Object
7. Symbol

1. Number

The Number classification of data type includes all numbers. Javascript has only one type of Numbers.

It includes:

Positive Number (6)
Negative Number (-2)
Floating Point Number (16.66)
Exponential Notation (25e+9), (25e-9)

Some programming languages have different Data Types for Integer, Floating point numbers. But in Javascript,

Only one datatype for all kind of Numbers

All mathematical operations are possible in Javascript. Addition, Subtraction, Multiplication, Division, Comparison etc.

2. String

In all programming languages ‘String’ means simply text. Just simple as that. We can use this data type to write meaningful sentences in human understandable language.

Rules to use string

1. Double quotes - "Hello, World!"
2. Singe quotes  - 'Hello, World!'
3. Backticks     - `Hello, World!`

Both double quotes and single quotes can be used for Strings. Both quotes have no difference. Javascript accepts as string whatever we write inside double quotes or single quotes.

Backticks has an extended functionality, used to embed some other values to the string. Will explain later.

What if we write a number inside the quotes like “21” .?

Now the datatype of digit“21” changed to String datatype ie., Data type number changed to String

3. Boolean

Boolean Data Type holds two values

1. True
2. False

Boolean is exactly like a switch.

Either it is ON or OFF.

1 or 0

For the sake of explanation, we can say Yes or No, else Correct or Incorrect. While writing the program we should write “true” and “false”

4. Null

Null Datatype is a type of its own. Null Datatype is exactly what it means in English. ie.,

Nothing

Empty

Zero (or)

Doesn’t exist

We can use ‘null’ for the cases where, if something is empty or unknown for some reason. Null Data Type holds a single value null.

5. Undefined

undefined is also a type of its own like Null. undefined means

“the value is not assigned”.

Say we have something, but we have not explained or defined, what exactly the “something” is, then it is an undefined.

Are undefined and null the same .?

No, null means zero and undefined means the value for a variable is not assigned

6. Object

In Object we can store a collection of data using a key : value pair

eg:

car  : Toyota
model: Corolla
year : 2012      

Above example is just for understanding, *incorrect syntax*. Object Data Type can be combined of String, Number, Boolean, null Data Types.

7. Symbol

Symbol is a new Data Type introduced in ES6, Use case of symbol data type is to create an unique identifier for Objects. Symbols are immutable. Symbol is a function and it holds the value of data type Symbol. Unique identifier here means, if we are taking two same values, normally we can say it is equivalent or the same. But if we defining that value in a Symbol function as Symbol Data Type it is not the same or not equal. Thus we can use it for uniqueness.

Normal case,    "Hello, World!" = "Hello, World!"                  // equals
Symbol Data type case,   
Symbol("Hello, World!") != Symbol("Hello, world!") // not equals

typeof Operator

typeof operator can be used to find what kind of Data Type is variable.

  1. Click the mouse on the right side of the blue > symbol.

  2. Type “typeof” , the suggestions will appear.

  3. There you can search for the type of Data.

PreviousJavaScript VariablesNextPrimitive and Non-Primitive

Last updated 5 years ago

Was this helpful?