SlideShare a Scribd company logo
A deeper look
into
Presentation By :
Ashutosh Mahto
Mindfire Solutions
Javascript Basics
“The world's most misunderstood programming language”
- Douglas Crockford
A Deeper Look Into Javascript Basics
Agenda to Discuss
Hoisting in javascript
Scopes In javascript
Objects
Functions
Closures
Prototype
Drawing some basic practices
A Deeper Look Into Javascript Basics
Hoisting in Javascript
A Deeper Look Into Javascript Basics
Every declaration, variable declaration or function declaration is hoisted to
the top of its declaration context.
/* Hoisiting */
var name = "ramesh";
function showName() {
if (!name) {
var name = "Suresh";
}
console.log(name);
}
showName(); // output - Suresh
Defining Scopes in Javascript
- Everything defined without var is global
- Every global variable or object can be accessed through
window.<variablename>
- Unlike C, Javascript doesn't have Block Level Scope
- Javascript has Function Level Scope
A Deeper Look Into Javascript Basics
Defining Scopes in Javascript
A Deeper Look Into Javascript Basics
#include <stdio.h>
int main() {
int x = 1;
printf("%d, ", x); // 1
if (1) {
int x = 2;
printf("%d, ", x); // 2
}
printf("%dn", x); // 1
}
var x = 1;
console.log(x); // 1
if (true) {
var x = 2;
console.log(x); // 2
}
console.log(x); ???
Output – 2, which should be 1 as
in C
Scope in C Scope in Javascript
Object In Javascript
- Everything except Number, String, Boolean, null and undefined
are objects.
- Can be created using object literals or through Object constructor.
- Objects are usually key value pairs.
- Objects can be used as Associative Arrays, but are not actually
any type of array.
- Objects can link to another objects through -
var newObject = Object(oldObject);
This will create a new object and keep a link to the Old Object.
If any property is not available in newObject it will be looked into
oldObject
A Deeper Look Into Javascript Basics
Functions In Javascript
- Executable piece of code, in any programming language.
- In javascript, functions are INVOKABLE objects.
- Like objects functions can carry Properties & Methods, can be
copied, deleted and augmented
- Functions can be passed as parameter to other functions and can
be returned also
- Functions are First Class Citizens in javascript.
- Every function returns a value, if not, returns undefined.
A Deeper Look Into Javascript Basics
Functions in Javascript
- Function declaration
function sayHello() {
console.log('Hello!');
}
- Function expression
var sayHello = function() {
console.log('Hello!');
}
- Anonymous Functions
- Self executing functions
(function() {
console.log('Hello!');
})();
A Deeper Look Into Javascript Basics
Closures in Javascript
Local variables for a function are kept alive after the function has
returned
A closure is a stack-frame which is not deallocated when the function
returns (as if a 'stack-frame' were malloc'ed instead of being on the
stack!)
A Deeper Look Into Javascript Basics
var greet = function(time) {
var good = "Good";
return function(name){
console.log(good+ " "+ time+ " "+ name);
}
}
var sayGoodMorning = greet("Morning");
sayGoodMorning("Suresh");
// Good Morning Suresh
Prototype in Javascript
Prototype is the base of Object Oriented Programming in javascript
Every function contains a prototype object that can be chained
through its constructor.
A Deeper Look Into Javascript Basics
var Person= function(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var student = new Person("Satish");
Drawing some best practices
Start using JSLint
Start using “strict”
Always use var while declaring variables to avoid unnecessary globals
Declare all the variables at the top of its function scope
Maximize the use of function expressions
Always use ; as delimiter
Never think of Objects as a kind of array, and never declare an object
as an array.
A Deeper Look Into Javascript Basics
Any Question ???
A Deeper Look Into Javascript Basics
References and Recommendations

Books
− JavascriptThe Good Parts, Douglas Crockford
− Javascript:The Definitive Guide, David Flanagan
− Professional Javascript For Developers, Nicholas Zakas

Blogs

Articles

Stack Overflow
A Deeper Look Into Javascript Basics
ThankYou !!!
A Deeper Look Into Javascript Basics

More Related Content

What's hot (20)

ODP
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
PDF
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
PPTX
Javascript 101
Shlomi Komemi
 
PPTX
Java script
Abhishek Kesharwani
 
PPTX
Angular modules in depth
Christoffer Noring
 
PPTX
Reactjs
Neha Sharma
 
PDF
TypeScript Introduction
Dmitry Sheiko
 
PPT
JavaScript Tutorial
Bui Kiet
 
PDF
Bootstrap
Jadson Santos
 
PPT
Javascript
guest03a6e6
 
PPTX
Bootstrap 5 ppt
Mallikarjuna G D
 
PDF
An introduction to React.js
Emanuele DelBono
 
PPT
jQuery
Mostafa Bayomi
 
PDF
Javascript essentials
Bedis ElAchèche
 
PDF
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
PPT
Js ppt
Rakhi Thota
 
PPTX
Introduction to Node js
Akshay Mathur
 
PDF
Basics of JavaScript
Bala Narayanan
 
PPTX
ReactJS presentation.pptx
DivyanshGupta922023
 
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
Javascript 101
Shlomi Komemi
 
Java script
Abhishek Kesharwani
 
Angular modules in depth
Christoffer Noring
 
Reactjs
Neha Sharma
 
TypeScript Introduction
Dmitry Sheiko
 
JavaScript Tutorial
Bui Kiet
 
Bootstrap
Jadson Santos
 
Javascript
guest03a6e6
 
Bootstrap 5 ppt
Mallikarjuna G D
 
An introduction to React.js
Emanuele DelBono
 
Javascript essentials
Bedis ElAchèche
 
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
Js ppt
Rakhi Thota
 
Introduction to Node js
Akshay Mathur
 
Basics of JavaScript
Bala Narayanan
 
ReactJS presentation.pptx
DivyanshGupta922023
 

Viewers also liked (8)

PDF
Js interpreter interpreted
Martha Schumann
 
PDF
Extending built in objects
Muhammad Ahmed
 
PPT
Array
mussawir20
 
PPT
JavaScript Event Loop
Thomas Hunter II
 
PDF
Node.js in action
Simon Su
 
PDF
Advanced Object-Oriented JavaScript
ecker
 
PPTX
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
PPTX
JavaScript Event Loop
Designveloper
 
Js interpreter interpreted
Martha Schumann
 
Extending built in objects
Muhammad Ahmed
 
Array
mussawir20
 
JavaScript Event Loop
Thomas Hunter II
 
Node.js in action
Simon Su
 
Advanced Object-Oriented JavaScript
ecker
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
raja kvk
 
JavaScript Event Loop
Designveloper
 
Ad

Similar to A Deeper look into Javascript Basics (20)

PPTX
Functions and Objects in JavaScript
Dhananjay Kumar
 
PPTX
OO in JavaScript
Gunjan Kumar
 
PPT
JavaScript Misunderstood
Bhavya Siddappa
 
PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
PPTX
JavaScript in Object-Oriented Way
Chamnap Chhorn
 
PPTX
Art of Javascript
Tarek Yehia
 
KEY
The JavaScript Programming Primer
Mike Wilcox
 
PDF
Javascript
Aditya Gaur
 
PDF
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion
 
PPT
eXo SEA - JavaScript Introduction Training
Hoat Le
 
KEY
Week3
Will Gaybrick
 
PPTX
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
PPT
JavaScript Workshop
Pamela Fox
 
KEY
Javascript unit testing, yes we can e big
Andy Peterson
 
PPTX
JavaScript code academy - introduction
Jaroslav Kubíček
 
PPTX
Java scriptforjavadev part2a
Makarand Bhatambarekar
 
KEY
JavaScript Growing Up
David Padbury
 
PPTX
Object oriented javascript
Usman Mehmood
 
PDF
Metaprogramming in JavaScript
Mehdi Valikhani
 
Functions and Objects in JavaScript
Dhananjay Kumar
 
OO in JavaScript
Gunjan Kumar
 
JavaScript Misunderstood
Bhavya Siddappa
 
OOPS JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
Javascriptinobject orientedway-090512225827-phpapp02
Sopheak Sem
 
JavaScript in Object-Oriented Way
Chamnap Chhorn
 
Art of Javascript
Tarek Yehia
 
The JavaScript Programming Primer
Mike Wilcox
 
Javascript
Aditya Gaur
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion
 
eXo SEA - JavaScript Introduction Training
Hoat Le
 
JavaScript Basics - GameCraft Training
Radoslav Georgiev
 
JavaScript Workshop
Pamela Fox
 
Javascript unit testing, yes we can e big
Andy Peterson
 
JavaScript code academy - introduction
Jaroslav Kubíček
 
Java scriptforjavadev part2a
Makarand Bhatambarekar
 
JavaScript Growing Up
David Padbury
 
Object oriented javascript
Usman Mehmood
 
Metaprogramming in JavaScript
Mehdi Valikhani
 
Ad

More from Mindfire Solutions (20)

PDF
Physician Search and Review
Mindfire Solutions
 
PDF
diet management app
Mindfire Solutions
 
PDF
Business Technology Solution
Mindfire Solutions
 
PDF
Remote Health Monitoring
Mindfire Solutions
 
PDF
Influencer Marketing Solution
Mindfire Solutions
 
PPT
High Availability of Azure Applications
Mindfire Solutions
 
PPTX
IOT Hands On
Mindfire Solutions
 
PPTX
Glimpse of Loops Vs Set
Mindfire Solutions
 
ODP
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
PPT
Adaptive Layout In iOS 8
Mindfire Solutions
 
PPT
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
PPT
LINQPad - utility Tool
Mindfire Solutions
 
PPT
Get started with watch kit development
Mindfire Solutions
 
PPTX
Swift vs Objective-C
Mindfire Solutions
 
ODP
Material Design in Android
Mindfire Solutions
 
ODP
Introduction to OData
Mindfire Solutions
 
PPT
Ext js Part 2- MVC
Mindfire Solutions
 
PPT
ExtJs Basic Part-1
Mindfire Solutions
 
PPT
Spring Security Introduction
Mindfire Solutions
 
Physician Search and Review
Mindfire Solutions
 
diet management app
Mindfire Solutions
 
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Mindfire Solutions
 
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Mindfire Solutions
 

Recently uploaded (20)

PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Digital Circuits, important subject in CS
contactparinay1
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 

A Deeper look into Javascript Basics

  • 1. A deeper look into Presentation By : Ashutosh Mahto Mindfire Solutions Javascript Basics
  • 2. “The world's most misunderstood programming language” - Douglas Crockford A Deeper Look Into Javascript Basics
  • 3. Agenda to Discuss Hoisting in javascript Scopes In javascript Objects Functions Closures Prototype Drawing some basic practices A Deeper Look Into Javascript Basics
  • 4. Hoisting in Javascript A Deeper Look Into Javascript Basics Every declaration, variable declaration or function declaration is hoisted to the top of its declaration context. /* Hoisiting */ var name = "ramesh"; function showName() { if (!name) { var name = "Suresh"; } console.log(name); } showName(); // output - Suresh
  • 5. Defining Scopes in Javascript - Everything defined without var is global - Every global variable or object can be accessed through window.<variablename> - Unlike C, Javascript doesn't have Block Level Scope - Javascript has Function Level Scope A Deeper Look Into Javascript Basics
  • 6. Defining Scopes in Javascript A Deeper Look Into Javascript Basics #include <stdio.h> int main() { int x = 1; printf("%d, ", x); // 1 if (1) { int x = 2; printf("%d, ", x); // 2 } printf("%dn", x); // 1 } var x = 1; console.log(x); // 1 if (true) { var x = 2; console.log(x); // 2 } console.log(x); ??? Output – 2, which should be 1 as in C Scope in C Scope in Javascript
  • 7. Object In Javascript - Everything except Number, String, Boolean, null and undefined are objects. - Can be created using object literals or through Object constructor. - Objects are usually key value pairs. - Objects can be used as Associative Arrays, but are not actually any type of array. - Objects can link to another objects through - var newObject = Object(oldObject); This will create a new object and keep a link to the Old Object. If any property is not available in newObject it will be looked into oldObject A Deeper Look Into Javascript Basics
  • 8. Functions In Javascript - Executable piece of code, in any programming language. - In javascript, functions are INVOKABLE objects. - Like objects functions can carry Properties & Methods, can be copied, deleted and augmented - Functions can be passed as parameter to other functions and can be returned also - Functions are First Class Citizens in javascript. - Every function returns a value, if not, returns undefined. A Deeper Look Into Javascript Basics
  • 9. Functions in Javascript - Function declaration function sayHello() { console.log('Hello!'); } - Function expression var sayHello = function() { console.log('Hello!'); } - Anonymous Functions - Self executing functions (function() { console.log('Hello!'); })(); A Deeper Look Into Javascript Basics
  • 10. Closures in Javascript Local variables for a function are kept alive after the function has returned A closure is a stack-frame which is not deallocated when the function returns (as if a 'stack-frame' were malloc'ed instead of being on the stack!) A Deeper Look Into Javascript Basics var greet = function(time) { var good = "Good"; return function(name){ console.log(good+ " "+ time+ " "+ name); } } var sayGoodMorning = greet("Morning"); sayGoodMorning("Suresh"); // Good Morning Suresh
  • 11. Prototype in Javascript Prototype is the base of Object Oriented Programming in javascript Every function contains a prototype object that can be chained through its constructor. A Deeper Look Into Javascript Basics var Person= function(name) { this.name = name; } Person.prototype.getName = function() { return this.name; } var student = new Person("Satish");
  • 12. Drawing some best practices Start using JSLint Start using “strict” Always use var while declaring variables to avoid unnecessary globals Declare all the variables at the top of its function scope Maximize the use of function expressions Always use ; as delimiter Never think of Objects as a kind of array, and never declare an object as an array. A Deeper Look Into Javascript Basics
  • 13. Any Question ??? A Deeper Look Into Javascript Basics
  • 14. References and Recommendations  Books − JavascriptThe Good Parts, Douglas Crockford − Javascript:The Definitive Guide, David Flanagan − Professional Javascript For Developers, Nicholas Zakas  Blogs  Articles  Stack Overflow A Deeper Look Into Javascript Basics
  • 15. ThankYou !!! A Deeper Look Into Javascript Basics

Editor's Notes

  • #3: Every developer starts his journey with C, and in most of the cases till he reaches upto web development he gains sufficient knowledge in C, C++, C# or may be Java at least. And here starts the problem. When it comes to javascript most of us usually ignore the basics of javascript assuming its the same, except few array declaration, weak typing etc. So this seminar is not intended to touch the basic declaration, initialization concepts but something additional to that.