SlideShare a Scribd company logo
JAVASCRIPT - GOOD PARTS
Manohar Shetty || Supriya Anand
SESSION-1
Efforts put in to make a robot called Javascript
SESSION-2
Play with javascipt - alerts, console.logs and what not.
SESSION-2
Frustated! Why somethings work and somethings don't?
I am bad... very very bad.
GLOBAL VARIABLES
No linker. Global namespace. Variable collisions!
//Your code
function foo() {
if (false) {
var x = 1;
}
return;
var y = 1;
}
//How Javascript interprets it
function foo() {
var x, y;
if (false) {
x = 1;
}
return;
y = 1;
}
'+'
Adds and concatenates.
Un-predictable and error prone
0 + "1"
// returns "01"
"3" + 1
// returns "31"
"3" - "2"
// returns 1
SEMICOLON INSERTION
Semi-colons are INSERTED by the parser
Optional semi-colons are not a “language feature”
You are not warned!! .... 'Uh oh..'
“JavaScript: where forgetting the occasional
semicolon isn't necessarily the end of the
world.”
NOT WHAT YOU EXPECT
TYPEOF()
typeof('abc’) -> string -> Nice
typeof(1) -> number -> Good
typeof({}) -> object -> Great
typeof([1,2,3]) -> object -> Ooops
typeof(null) -> object -> WTH
Javascript good parts - for novice programmers
AGAIN..
== AND !=
‘ ’ == 0 -> false
0 == ‘ ‘ -> true
false == ‘false’ -> false
false == ‘0’ -> true
false == undefined -> false
undefined == null -> true
Javascript good parts - for novice programmers
FLOATING POINTS
0.1 + 0.2 = 0.3 //Nope, back to grade 1 you go!
> 0.1 + 0.2 == 0.3
false
> 0.1 + 0.2 = 0.30000000000000004
WHAT?!
STYLE IS NOT SUBJECTIVE
return {
status: ‘OK’
}
return
{
status: ‘OK’
}
return;
{
status: ‘OK’;
}
OKAY, ENOUGH OF THE BAD!
Show me the good!!
FINALLY, LETS TALK ABOUT THE GOOD.
OBJECT LITERALS
var obj = {
name: 'manohar',
age: 23
}
Pass as options to functions
JSON for communication, remember API's anyone?
DYNAMIC OBJECTS
Members can be added to any object, any time
Helpful to attach attributes
var obj = {
count: 2,
getCount: function(){
return this.count;
}
}
obj.incrementCount = function(){
this.count++;
}
obj.incrementCount();
alert(obj.getCount()); // 3
LOOSELY TYPED
/* JavaScript Example (loose typing) */
var a = 13; // Number declaration
var b = "thirteen"; // String declaration
b=a // b = 13
/* Java Example (strong typing) */
int a = 13; // int declaration
String b = "thirteen"; // String declaration
FUNCTIONS ARE OBJECTS
can be passed, returned
var fibonacci = function(number) {
number < 2 ? number : fibonacci(number -1 ) + fibonacci(number - 2)
}
LAMBDA / CLOSURES
a closure is a reference to the local vars for a function -
local vars 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!)
function, inner function, outer function, function inside
function, this function, that function
CONFUSED?
CLOSURES, IN ACTION
var wishPeople = function(){
var names = ['manohar', 'supriya', 'hari', 'DP'];
var wish = function(){
for(i=0, n=names.length; i < n;i++) {
console.log("Hello!" + names[i] + ". Welcome to Women Who Code meetup
}
};
return wish;
}();
wishPeople();
Prototypal Inheritance
Memoization
Callbacks
scope
AND MORE!
Javascript good parts - for novice programmers
www.mavenhive.in

More Related Content

PPTX
PDF
Swift Introduction
PDF
Workhop iOS 1: Fundamentos de Swift
PDF
Denis Lebedev, Swift
PPTX
All You Need to Know About Type Script
PDF
Cocoa Design Patterns in Swift
PPTX
SWIFT 3
PDF
Introduction to Swift
Swift Introduction
Workhop iOS 1: Fundamentos de Swift
Denis Lebedev, Swift
All You Need to Know About Type Script
Cocoa Design Patterns in Swift
SWIFT 3
Introduction to Swift

What's hot (20)

PDF
Swift - the future of iOS app development
PDF
Swift Programming Language
PDF
Swift Programming
PDF
Swift Programming Language
PDF
WDB005.1 - JavaScript for Java Developers (Lecture 1)
PDF
A Re-Introduction to JavaScript
PPTX
PHP: GraphQL consistency through code generation
PDF
Javascript status 2016
PPT
Introduction to Javascript
PPTX
Ruby from zero to hero
PDF
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
PDF
JavaScript 101 - Class 1
PDF
JavaScript For CSharp Developer
PPTX
Javascript basics for automation testing
PDF
⚛️ Reasonable React (with beers)
PDF
Coffee script
PDF
Working with Cocoa and Objective-C
PPT
The JavaScript Programming Language
PDF
Hipster Oriented Programming
PPT
JavaScript Tutorial
Swift - the future of iOS app development
Swift Programming Language
Swift Programming
Swift Programming Language
WDB005.1 - JavaScript for Java Developers (Lecture 1)
A Re-Introduction to JavaScript
PHP: GraphQL consistency through code generation
Javascript status 2016
Introduction to Javascript
Ruby from zero to hero
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript 101 - Class 1
JavaScript For CSharp Developer
Javascript basics for automation testing
⚛️ Reasonable React (with beers)
Coffee script
Working with Cocoa and Objective-C
The JavaScript Programming Language
Hipster Oriented Programming
JavaScript Tutorial
Ad

Viewers also liked (20)

PPT
Strings
PPTX
Bringbestoinyou
PPTX
Functions and Objects in JavaScript
PDF
ODP
Object Oriented Javascript
PDF
Datatype
PPT
Javascript by geetanjali
PPTX
Javascript - Array - Writing
PPT
Tree and Binary Search tree
PDF
javascript objects
PPTX
Javascript - Array - Creating Array
PDF
Learn REST in 18 Slides
PDF
Good Parts of JavaScript Douglas Crockford
PDF
The JavaScript You Wished You Knew
PDF
JavaScript - From Birth To Closure
PPTX
Structure of url, uniform resource locator
PDF
JavaScript Functions
PPTX
Javascript para principiantes -Introducción
PDF
Introduction to JSON
PPTX
Basics of computer science
Strings
Bringbestoinyou
Functions and Objects in JavaScript
Object Oriented Javascript
Datatype
Javascript by geetanjali
Javascript - Array - Writing
Tree and Binary Search tree
javascript objects
Javascript - Array - Creating Array
Learn REST in 18 Slides
Good Parts of JavaScript Douglas Crockford
The JavaScript You Wished You Knew
JavaScript - From Birth To Closure
Structure of url, uniform resource locator
JavaScript Functions
Javascript para principiantes -Introducción
Introduction to JSON
Basics of computer science
Ad

Similar to Javascript good parts - for novice programmers (20)

PPT
JavaScript - Programming Languages course
PDF
JavaScript Good Practices
PPTX
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
KEY
JavaScript @ CTK
PPT
Wakanday JS201 Best Practices
PPTX
PDF
Web 4 | Core JavaScript
PPT
Goodparts
PPT
A Deeper look into Javascript Basics
PPT
Javascript
PPTX
Awesomeness of JavaScript…almost
PDF
JavaScript introduction 1 ( Variables And Values )
PDF
Let's JavaScript
ODP
jsbasics-slide
PPTX
The JavaScript Programming Language
PDF
Javascript development done right
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
PDF
JavaScript Basics and Best Practices - CC FE & UX
PPTX
Intro to Javascript
PDF
Javascript - Tutorial
JavaScript - Programming Languages course
JavaScript Good Practices
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript @ CTK
Wakanday JS201 Best Practices
Web 4 | Core JavaScript
Goodparts
A Deeper look into Javascript Basics
Javascript
Awesomeness of JavaScript…almost
JavaScript introduction 1 ( Variables And Values )
Let's JavaScript
jsbasics-slide
The JavaScript Programming Language
Javascript development done right
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
JavaScript Basics and Best Practices - CC FE & UX
Intro to Javascript
Javascript - Tutorial

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Welding lecture in detail for understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Sustainable Sites - Green Building Construction
PPT
Project quality management in manufacturing
PPTX
Construction Project Organization Group 2.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Well-logging-methods_new................
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
composite construction of structures.pdf
PPT
Drone Technology Electronics components_1
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Welding lecture in detail for understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Sustainable Sites - Green Building Construction
Project quality management in manufacturing
Construction Project Organization Group 2.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Well-logging-methods_new................
Lesson 3_Tessellation.pptx finite Mathematics
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Foundation to blockchain - A guide to Blockchain Tech
Internet of Things (IOT) - A guide to understanding
bas. eng. economics group 4 presentation 1.pptx
composite construction of structures.pdf
Drone Technology Electronics components_1
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Operating System & Kernel Study Guide-1 - converted.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026

Javascript good parts - for novice programmers

  • 1. JAVASCRIPT - GOOD PARTS Manohar Shetty || Supriya Anand
  • 2. SESSION-1 Efforts put in to make a robot called Javascript
  • 3. SESSION-2 Play with javascipt - alerts, console.logs and what not.
  • 4. SESSION-2 Frustated! Why somethings work and somethings don't?
  • 5. I am bad... very very bad.
  • 6. GLOBAL VARIABLES No linker. Global namespace. Variable collisions! //Your code function foo() { if (false) { var x = 1; } return; var y = 1; } //How Javascript interprets it function foo() { var x, y; if (false) { x = 1; } return; y = 1; }
  • 7. '+' Adds and concatenates. Un-predictable and error prone 0 + "1" // returns "01" "3" + 1 // returns "31" "3" - "2" // returns 1
  • 8. SEMICOLON INSERTION Semi-colons are INSERTED by the parser Optional semi-colons are not a “language feature” You are not warned!! .... 'Uh oh..' “JavaScript: where forgetting the occasional semicolon isn't necessarily the end of the world.”
  • 9. NOT WHAT YOU EXPECT TYPEOF() typeof('abc’) -> string -> Nice typeof(1) -> number -> Good typeof({}) -> object -> Great typeof([1,2,3]) -> object -> Ooops typeof(null) -> object -> WTH
  • 11. AGAIN.. == AND != ‘ ’ == 0 -> false 0 == ‘ ‘ -> true false == ‘false’ -> false false == ‘0’ -> true false == undefined -> false undefined == null -> true
  • 13. FLOATING POINTS 0.1 + 0.2 = 0.3 //Nope, back to grade 1 you go! > 0.1 + 0.2 == 0.3 false > 0.1 + 0.2 = 0.30000000000000004 WHAT?!
  • 14. STYLE IS NOT SUBJECTIVE return { status: ‘OK’ } return { status: ‘OK’ } return; { status: ‘OK’; }
  • 15. OKAY, ENOUGH OF THE BAD! Show me the good!!
  • 16. FINALLY, LETS TALK ABOUT THE GOOD.
  • 17. OBJECT LITERALS var obj = { name: 'manohar', age: 23 } Pass as options to functions JSON for communication, remember API's anyone?
  • 18. DYNAMIC OBJECTS Members can be added to any object, any time Helpful to attach attributes var obj = { count: 2, getCount: function(){ return this.count; } } obj.incrementCount = function(){ this.count++; } obj.incrementCount(); alert(obj.getCount()); // 3
  • 19. LOOSELY TYPED /* JavaScript Example (loose typing) */ var a = 13; // Number declaration var b = "thirteen"; // String declaration b=a // b = 13 /* Java Example (strong typing) */ int a = 13; // int declaration String b = "thirteen"; // String declaration
  • 20. FUNCTIONS ARE OBJECTS can be passed, returned var fibonacci = function(number) { number < 2 ? number : fibonacci(number -1 ) + fibonacci(number - 2) }
  • 21. LAMBDA / CLOSURES a closure is a reference to the local vars for a function - local vars 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!) function, inner function, outer function, function inside function, this function, that function CONFUSED?
  • 22. CLOSURES, IN ACTION var wishPeople = function(){ var names = ['manohar', 'supriya', 'hari', 'DP']; var wish = function(){ for(i=0, n=names.length; i < n;i++) { console.log("Hello!" + names[i] + ". Welcome to Women Who Code meetup } }; return wish; }(); wishPeople();