SlideShare uma empresa Scribd logo
1 de 12
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.

Mais conteúdo relacionado

Mais procurados

Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http clientGaurav Madaan
 
웹 Front-End 실무 이야기
웹 Front-End 실무 이야기웹 Front-End 실무 이야기
웹 Front-End 실무 이야기JinKwon Lee
 
How to earn a black belt in Graphql testing
How to earn a black belt in Graphql testingHow to earn a black belt in Graphql testing
How to earn a black belt in Graphql testingLuca Pelosi
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library 10Clouds
 
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기YoungjikYoon
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Pece Nikolovski
 
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델명환 안
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST Ram Awadh Prasad, PMP
 
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기AWS 기반 마이크로 프론트엔드 아키텍처 구축하기
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기Eunsu Kim
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMarlon Jamera
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js SimplifiedSunil Yadav
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018Paulo Clavijo
 

Mais procurados (20)

Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
 
웹 Front-End 실무 이야기
웹 Front-End 실무 이야기웹 Front-End 실무 이야기
웹 Front-End 실무 이야기
 
Kotlin Multiplatform
Kotlin MultiplatformKotlin Multiplatform
Kotlin Multiplatform
 
How to earn a black belt in Graphql testing
How to earn a black belt in Graphql testingHow to earn a black belt in Graphql testing
How to earn a black belt in Graphql testing
 
What’s New in Angular 14?
What’s New in Angular 14?What’s New in Angular 14?
What’s New in Angular 14?
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기
Gradle Kotlin 컨벤션 플러그인으로 효율적으로 멀티 모듈 관리하기
 
Meaning Of VB
Meaning Of VBMeaning Of VB
Meaning Of VB
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
 
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Mongodb
MongodbMongodb
Mongodb
 
4.3 MySQL + PHP
4.3 MySQL + PHP4.3 MySQL + PHP
4.3 MySQL + PHP
 
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기AWS 기반 마이크로 프론트엔드 아키텍처 구축하기
AWS 기반 마이크로 프론트엔드 아키텍처 구축하기
 
Java script
Java scriptJava script
Java script
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
 

Semelhante a Interesting Facts About Javascript

Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep DiveManish Jangir
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1Martin Pernica
 
A JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsA JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsShahriar Hyder
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
 
An SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHPAn SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHPTroyfawkes
 
javascript
javascript javascript
javascript Kaya Ota
 
As Triage Code Camp
As Triage Code CampAs Triage Code Camp
As Triage Code CampRob Sawyer
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayChamnap Chhorn
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQueryBobby Bryant
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorialmustafa sarac
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfranjanadeore1
 

Semelhante a Interesting Facts About Javascript (20)

Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1
 
A JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsA JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFs
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Javascript analysis
Javascript analysisJavascript analysis
Javascript analysis
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
An SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHPAn SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHP
 
javascript
javascript javascript
javascript
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
 
As Triage Code Camp
As Triage Code CampAs Triage Code Camp
As Triage Code Camp
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQuery
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorial
 
Java script basic
Java script basicJava script basic
Java script basic
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
S.k
S.kS.k
S.k
 
Java script
Java scriptJava script
Java script
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 

Último

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Último (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

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.