SlideShare a Scribd company logo
Interesting Facts About
Javascript
--Manish Jangir--
Introduction
Why I’ve named this presentation as “Interesting Facts About Javascript” because
there is a whole lot of things we still do accidently in javascript without actually
knowing that how it works.
This presentation will literally break a lot of misconceptions about Javascript
behaviour you might have put in your mind.
So without wasting anymore time, let's quickly jump to the very basic javascript
fundamental thing types.
Data Types In Javascript
Many of you might have worked a little (may be in college time) in statically typed
language like “C” and here you are working in Javascript as a dynamically typed
language. So what is statically typed and dynamically typed language?
In statically typed language, each variable you declare must have a type
associated with it so that the compiler can allocate the proper memory for it.
But in dynamically typed language, the variables don’t have any type to be
associated to it. Did you ever declared a variable as integer, string or boolean??
So javascript is dynamically typed language. But why the hell we have some data
types there in Javascript????
Data Types In Javascript Contd….
As we have seen in our Javascript code that both we and the javascript engine
treat a value 30 differently than “30”. We consider 30 as a number but “30” as a
string.
What does it mean?
The above thing means that the value may have a specific type associated to it.
Value has a type or Variable??? Confused???
In javascript or any dynamically typed language, the variables are not associated
with any type. Remember, the values have type not the variables.
Means, var a = 5; means a is not type of “number” but the value in it is type of
“number”.
Value Types In Javascript
So now on, we will say it Value Types not Data Types. Basically there are 7 built-
in types there in Javascript.
1. null
2. undefined
3. boolean
4. number
5. string
6. object
7. symbol (in ES6)
All of the above types except object are primitive that means, they are passed by
value not reference. Objects are non-primitive values which are passed through
reference.
“typeof” Keyword In Javascript
How do you check that what typeof value a variable is holding? The very useful keyword typeof does this
for you. Whenever you check a value type, it will give you a string value out of the following 7 string
values.
In the above code, there are 8 lines but you can see that only 7 distinctly types are there. It means these
are the seven types you will get in a typeof expression. Here are two strange things we can see:
1. typeof null returns object while it is not object. How null can be an object type value.
2. typeof function returns function while we have talked many times that functions are objects.
Why typeof null Is Object??
Nothing to be surprised here. It's a 20 years old BUG in Javascript. Yes its a
bug that could not be fixed due to already having a large codebase on internet that
is dependant on typeof null === “object” expression.
Otherwise what we expect from the browser is typeof null should give us “null” as
string value.
If you want to check if variable has a null value type, check with the following
ways.
1. if(variable === null)
2. if(!variable && typeof variable == “object”). Null is the only falsy value, which
is false but still type of object.
“function” Type Value
In Javascript, we have seen that functions are just objects which can have static
properties on them. But they have been provided a specific type called
“function”.
Functions are kind of callable objects and have special place in Javascript
environment.
Undefined VS. Undeclared - Most Confusing
Variables which don’t have any value will have a specific hidden value called undefined. You can check it
with typeof keyword like below:
A lot of times, we see undefined and undeclared as same things but they don’t actually. An undefined
variable is that which has been declared but not assigned any kind of value. Where an undeclared
variable is that which has never been even declared in script.
Here the most confusing part is that error message. Don’t you see “ReferenceError b is not defined” is
exactly like “b is undefined”. But remember, undefined and is not defined are two completely different
things in Javascript.
Undefined VS. Undeclared - Continued….
It could be very nice if the javascript engine could tell us that ReferenceError: b is not found if the
variable is never declared. At Least it makes some sense.
One more confusing part:
Here you can see that if we put typeof on both the undefined and undeclared variables, it will return the
type value “undefined”. It means, typeof has a special behaviour that gives us flexibility to check whether
a variable is declared or not. It won’t throw error if the variable is not declared.
The most common use of typeof is to check if we want to check any third party library global object like
typeof jQuery !== ‘undefined’ etc. It won’t throw error even if you have not included jQuery in your script.
Arrays In Javascript
How many of you have enough understanding of Javascript Arrays?
Arrays are just a kind of container that hold any type of value. Whether it is string, number, boolean, object
or another array (Multidimensional).
You never need to define size of the array first. You can declare it and push values directly. For e.g.
Delete A Value From Array
Never get trapped by the keyword delete. Though it will delete the value from array but will not behave
exactly like you thought. For example:
Using keyword delete will delete the value but will not actually re-index the array. What it will do is just
make the slot empty. In the above example the slot at index 1 will actually have no value and that's why, it
show undefined in log. So even deleting all the value from array with delete keyword, it will not update the
length of the array.
Instead use array.splice(1,1) which will remove the value from index 1 to 1 number of values.

More Related Content

What's hot (20)

PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PPT
Introduction to Javascript
Amit Tyagi
 
PPT
Inheritance OOP Concept in C++.
MASQ Technologies
 
PPSX
OOP with Java - Part 3
Hitesh-Java
 
PPTX
Introduction to JSX
Micah Wood
 
ODP
Exception Handling In Java
parag
 
PPTX
Javascript Objects Deep Dive
Manish Jangir
 
PPTX
OOPS IN C++
Amritsinghmehra
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPTX
Standard Template Library
GauravPatil318
 
PPTX
Introduction of sql server indexing
Mahabubur Rahaman
 
PDF
How to use Map() Filter() and Reduce() functions in Python | Edureka
Edureka!
 
PPTX
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
PPTX
Asp objects
RajaRajeswari22
 
PDF
Nouveautés Java 9-10-11
Mahamadou TOURE, Ph.D.
 
PDF
Intro to Asynchronous Javascript
Garrett Welson
 
PDF
PHP and Mysql
Sankhadeep Roy
 
PPT
SOLID Design Principles
Andreas Enbohm
 
Jdbc architecture and driver types ppt
kamal kotecha
 
Introduction to Javascript
Amit Tyagi
 
Inheritance OOP Concept in C++.
MASQ Technologies
 
OOP with Java - Part 3
Hitesh-Java
 
Introduction to JSX
Micah Wood
 
Exception Handling In Java
parag
 
Javascript Objects Deep Dive
Manish Jangir
 
OOPS IN C++
Amritsinghmehra
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Standard Template Library
GauravPatil318
 
Introduction of sql server indexing
Mahabubur Rahaman
 
How to use Map() Filter() and Reduce() functions in Python | Edureka
Edureka!
 
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
Asp objects
RajaRajeswari22
 
Nouveautés Java 9-10-11
Mahamadou TOURE, Ph.D.
 
Intro to Asynchronous Javascript
Garrett Welson
 
PHP and Mysql
Sankhadeep Roy
 
SOLID Design Principles
Andreas Enbohm
 

Similar to Interesting Facts About Javascript (20)

PPT
JavaScript Data Types
Charles Russell
 
PDF
Java script summary
maamir farooq
 
PPTX
Javascript analysis
Uchitha Bandara
 
PDF
Js ch-1
Saritapol13
 
PPTX
Javascript
Prashant Kumar
 
PDF
Introduction to Javascript and Typescript.pdf
rony setyawansyah
 
PDF
JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
WT Unit-3 PPT.pptx
TusharTikia
 
PPTX
JavaScript Lecture notes.pptx
NishaRohit6
 
PPT
An introduction to javascript
MD Sayem Ahmed
 
KEY
JavaScript: Values, Types and Variables
LearnNowOnline
 
PPTX
Java script basic
Ravi Bhadauria
 
ODP
Datatype in JavaScript
Rajat Saxena
 
PPS
Master in javascript
Robbin Zhao
 
PPT
Javascript
Manav Prasad
 
PPT
Ajax and JavaScript Bootcamp
AndreCharland
 
PDF
Basics of JavaScript
Bala Narayanan
 
PDF
Type Checking JavaScript
Pascal-Louis Perez
 
ODP
Javascript
theacadian
 
PDF
Javascript
20261A05H0SRIKAKULAS
 
JavaScript Data Types
Charles Russell
 
Java script summary
maamir farooq
 
Javascript analysis
Uchitha Bandara
 
Js ch-1
Saritapol13
 
Javascript
Prashant Kumar
 
Introduction to Javascript and Typescript.pdf
rony setyawansyah
 
JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
WT Unit-3 PPT.pptx
TusharTikia
 
JavaScript Lecture notes.pptx
NishaRohit6
 
An introduction to javascript
MD Sayem Ahmed
 
JavaScript: Values, Types and Variables
LearnNowOnline
 
Java script basic
Ravi Bhadauria
 
Datatype in JavaScript
Rajat Saxena
 
Master in javascript
Robbin Zhao
 
Javascript
Manav Prasad
 
Ajax and JavaScript Bootcamp
AndreCharland
 
Basics of JavaScript
Bala Narayanan
 
Type Checking JavaScript
Pascal-Louis Perez
 
Javascript
theacadian
 
Ad

Recently uploaded (20)

PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Biography of Daniel Podor.pdf
Daniel Podor
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Ad

Interesting Facts About Javascript

  • 2. Introduction Why I’ve named this presentation as “Interesting Facts About Javascript” because there is a whole lot of things we still do accidently in javascript without actually knowing that how it works. This presentation will literally break a lot of misconceptions about Javascript behaviour you might have put in your mind. So without wasting anymore time, let's quickly jump to the very basic javascript fundamental thing types.
  • 3. Data Types In Javascript Many of you might have worked a little (may be in college time) in statically typed language like “C” and here you are working in Javascript as a dynamically typed language. So what is statically typed and dynamically typed language? In statically typed language, each variable you declare must have a type associated with it so that the compiler can allocate the proper memory for it. But in dynamically typed language, the variables don’t have any type to be associated to it. Did you ever declared a variable as integer, string or boolean?? So javascript is dynamically typed language. But why the hell we have some data types there in Javascript????
  • 4. Data Types In Javascript Contd…. As we have seen in our Javascript code that both we and the javascript engine treat a value 30 differently than “30”. We consider 30 as a number but “30” as a string. What does it mean? The above thing means that the value may have a specific type associated to it. Value has a type or Variable??? Confused??? In javascript or any dynamically typed language, the variables are not associated with any type. Remember, the values have type not the variables. Means, var a = 5; means a is not type of “number” but the value in it is type of “number”.
  • 5. Value Types In Javascript So now on, we will say it Value Types not Data Types. Basically there are 7 built- in types there in Javascript. 1. null 2. undefined 3. boolean 4. number 5. string 6. object 7. symbol (in ES6) All of the above types except object are primitive that means, they are passed by value not reference. Objects are non-primitive values which are passed through reference.
  • 6. “typeof” Keyword In Javascript How do you check that what typeof value a variable is holding? The very useful keyword typeof does this for you. Whenever you check a value type, it will give you a string value out of the following 7 string values. In the above code, there are 8 lines but you can see that only 7 distinctly types are there. It means these are the seven types you will get in a typeof expression. Here are two strange things we can see: 1. typeof null returns object while it is not object. How null can be an object type value. 2. typeof function returns function while we have talked many times that functions are objects.
  • 7. Why typeof null Is Object?? Nothing to be surprised here. It's a 20 years old BUG in Javascript. Yes its a bug that could not be fixed due to already having a large codebase on internet that is dependant on typeof null === “object” expression. Otherwise what we expect from the browser is typeof null should give us “null” as string value. If you want to check if variable has a null value type, check with the following ways. 1. if(variable === null) 2. if(!variable && typeof variable == “object”). Null is the only falsy value, which is false but still type of object.
  • 8. “function” Type Value In Javascript, we have seen that functions are just objects which can have static properties on them. But they have been provided a specific type called “function”. Functions are kind of callable objects and have special place in Javascript environment.
  • 9. Undefined VS. Undeclared - Most Confusing Variables which don’t have any value will have a specific hidden value called undefined. You can check it with typeof keyword like below: A lot of times, we see undefined and undeclared as same things but they don’t actually. An undefined variable is that which has been declared but not assigned any kind of value. Where an undeclared variable is that which has never been even declared in script. Here the most confusing part is that error message. Don’t you see “ReferenceError b is not defined” is exactly like “b is undefined”. But remember, undefined and is not defined are two completely different things in Javascript.
  • 10. Undefined VS. Undeclared - Continued…. It could be very nice if the javascript engine could tell us that ReferenceError: b is not found if the variable is never declared. At Least it makes some sense. One more confusing part: Here you can see that if we put typeof on both the undefined and undeclared variables, it will return the type value “undefined”. It means, typeof has a special behaviour that gives us flexibility to check whether a variable is declared or not. It won’t throw error if the variable is not declared. The most common use of typeof is to check if we want to check any third party library global object like typeof jQuery !== ‘undefined’ etc. It won’t throw error even if you have not included jQuery in your script.
  • 11. Arrays In Javascript How many of you have enough understanding of Javascript Arrays? Arrays are just a kind of container that hold any type of value. Whether it is string, number, boolean, object or another array (Multidimensional). You never need to define size of the array first. You can declare it and push values directly. For e.g.
  • 12. Delete A Value From Array Never get trapped by the keyword delete. Though it will delete the value from array but will not behave exactly like you thought. For example: Using keyword delete will delete the value but will not actually re-index the array. What it will do is just make the slot empty. In the above example the slot at index 1 will actually have no value and that's why, it show undefined in log. So even deleting all the value from array with delete keyword, it will not update the length of the array. Instead use array.splice(1,1) which will remove the value from index 1 to 1 number of values.