SlideShare a Scribd company logo
Powerful JavaScript TipsPowerful JavaScript Tips
Techniques that all JavaScript programmers can use now
you needn’t be an advanced JavaScript developer to benefit from these tips
Powerful JavaScript TipsPowerful JavaScript Tips
1. “short circuting” method
To set default values, instead of this:
function fileName(name)
​ if (!name) {
name = "unknown_name";
}
return name;
}
Use this:
function fileName(name)
name = name || "unknown_name";
return name;
}
Powerful JavaScript TipsPowerful JavaScript Tips
2. “short circuting” with && (AND)
Instead of this:
function isAdult(age) {
if (age && age > 17) {
return true;
}
​else {
return false;
}
}
Use this:
function isAdult(age) {
return age && age > 17 ;
}
Powerful JavaScript TipsPowerful JavaScript Tips
3. It gets more exciting!
Instead of this:
if (userName) {
logIn(userName);
}
else {
signUp();
}
Use this:
userName && logIn (userName) || signUp ();

Recommended for you

Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript

Slides from my "Object-oriented JavaScript" presentation at CSDN (China Software Developers Network), Beijing, December 2008

stoyannetworkdevelopers
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript

JavaScript is the programming language of the web. It can dynamically manipulate HTML content by changing element properties like innerHTML. Functions allow JavaScript code to run in response to events like button clicks or timeouts. JavaScript uses objects and prototypes to define reusable behaviors and properties for objects. It is an important language for web developers to learn alongside HTML and CSS.

JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions

Functions being first-class citizens in JavaScript offers developers a tremendous amount power and flexibilty. However, what good is all this power if you don't know how to harness it? This talk will provide a thorough examination of JavaScript functions. Topics that will be covered in this talk are: * Functions are objects * Execution Context and the Scope Chain * Closures * Modifying Context * The Various Forms of Functions. Attendees will leave this talk understanding the power of JavaScript functions and the knowledge to apply new techiques that will make their JavaScript cleaner, leaner and more maintainable.

javascript
Powerful JavaScript TipsPowerful JavaScript Tips
4. powerful uses of immediately invoked function expressions
Immediately and after invoke
(showName = function (name) {
console.log(name || "No Name")
}) (); // No Name​
​
showName ("Mike"); // Mike
Powerful JavaScript TipsPowerful JavaScript Tips
5. when to use immediately invoked function expressions?
All the code is wrapped in the IIFE​
(function () {
​var firstName = “Dragos”, concatenated = undefined;
function init () {
doStuff (firstName);
// code to start the application​
}
​
​function doStuff (firstName) {
concatenated = firstName + 'Developer';
doMoreStuff();
}
​
​function doMoreStuff () {
console.log('Concatenated = ', concatenated;
}
​
​// Start the application
init ();
}) ();
BONUSJavaScript Best Practices
JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.

Recommended for you

Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript

JavaScript has some stunning features like Closures, Prototype etc. which can help to improve the readability and maintainability of the code. However, it is not easy for inexperienced developer to consume and apply those features in day to day coding. The purpose of the presentation ‘Advanced JavaScript’ is to help a reader easily understand the concept and implementation of some advanced JavaScript features.

closuremodule patternprototype
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing

This document provides an overview of basic JavaScript examples and concepts. It covers topics such as writing JavaScript code, variables, conditional statements, functions, loops, events, and error handling. For each topic, it provides short code snippets to demonstrate the concept. It concludes by referencing W3Schools as a resource and thanking the reader.

javascript introductionjavascriptjavascript basics
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1

In JS: CLASS <=> Constructor FN new FN() => FN() { this } FN = CLASS (FN = FN, FN = DATA) Objects Prototype / __proto__ Inheritence Rewriting / Augmenting built in objects

oojsjava scriptinheritence
JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.
2 – use === instead of ==
JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.
2 – use === instead of ==
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.
2 – use === instead of ==
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
4 – Be careful when using typeof, instanceof and constructor.
typeof : a JavaScript unary operator used to return a string that represents the primitive
type of a variable, don’t forget that typeof null will return “object”,
and for the majority of object types (Array, Date, and others) will return also “object”.
constructor : is a property of the internal prototype property, which
could be overridden by code.
instanceof : is another JavaScript operator that check in all the prototypes chain the
constructor it returns true if it’s found and false if not.
JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.
2 – use === instead of ==
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
4 – Be careful when using typeof, instanceof and constructor.
typeof : a JavaScript unary operator used to return a string that represents the primitive
type of a variable, don’t forget that typeof null will return “object”,
and for the majority of object types (Array, Date, and others) will return also “object”.
constructor : is a property of the internal prototype property, which
could be overridden by code.
instanceof : is another JavaScript operator that check in all the prototypes chain the
constructor it returns true if it’s found and false if not.
5 – Get a random item from an array
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];
var randomItem = items[Math.floor(Math.random() * items.length)];

Recommended for you

JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics

The document provides an overview of JavaScript, covering what it is, its basics, functions, objects, prototypes, scope, asynchronous JavaScript, JSON, debugging tools, performance, events, error handling, and the future of JavaScript. It discusses that JavaScript is an object-oriented scripting language used in web pages that is not tied to specific browsers but makes use of the DOM, BOM, and ECMAScript standards. It also summarizes some of JavaScript's core features like functions, objects, prototypes, and more.

javascript
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...

This talk takes a deep dive into asynchronous programming patterns and practices, with an emphasis on the promise pattern. We go through the basics of the event loop, highlighting the drawbacks of asynchronous programming in a naive callback style. Fortunately, we can use the magic of promises to escape from callback hell with a powerful and unified interface for async APIs. Finally, we take a quick look at the possibilities for using coroutines both in current and future (ECMAScript Harmony) JavaScript.

javascriptpromisesajax
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript

This document provides an introduction to JavaScript including: - JavaScript is an object-oriented scripting language that is a dialect of ECMAScript. - It was originally designed to add interactivity to HTML pages through dynamic HTML, reacting to events, and data validation. - JavaScript is now heavily used in AJAX-based sites to asynchronously retrieve and display data without reloading pages. - The document discusses JavaScript compatibility issues and provides examples of basic JavaScript concepts like variables, comparisons, repetition, and popup boxes.

JavaScript Best Practices
1 – Don’t forget var keyword when assigning a variable’s value for the first time.
2 – use === instead of ==
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
4 – Be careful when using typeof, instanceof and constructor.
typeof : a JavaScript unary operator used to return a string that represents the primitive
type of a variable, don’t forget that typeof null will return “object”,
and for the majority of object types (Array, Date, and others) will return also “object”.
constructor : is a property of the internal prototype property, which
could be overridden by code.
instanceof : is another JavaScript operator that check in all the prototypes chain the
constructor it returns true if it’s found and false if not.
5 – Get a random item from an array
3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];
var randomItem = items[Math.floor(Math.random() * items.length)];
6 – Generate an array of numbers with numbers from 0 to max
var numbersArray = [] , max = 100;
for( var i=1; numbersArray.push(i++) < max;); // numbers = [1,2,3 ... 100]
JavaScript Best Practices
7 – Append an array to another array
var array1 = [12 , "foo" , {name "Joe"} , -2458];
var array2 = ["Doe" , 555 , 100];
Array.prototype.push.apply(array1, array2);
/* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
JavaScript Best Practices
7 – Append an array to another array`
var array1 = [12 , "foo" , {name "Joe"} , -2458];
var array2 = ["Doe" , 555 , 100];
Array.prototype.push.apply(array1, array2);
/* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
8 – Transform the arguments object into an array
var argArray = Array.prototype.slice.call(arguments);
JavaScript Best Practices
7 – Append an array to another array`
var array1 = [12 , "foo" , {name "Joe"} , -2458];
var array2 = ["Doe" , 555 , 100];
Array.prototype.push.apply(array1, array2);
/* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
8 – Transform the arguments object into an array
var argArray = Array.prototype.slice.call(arguments);
9 – Verify that a given argument is a number
function isNumber(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}

Recommended for you

Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns

This document discusses several common JavaScript design patterns including Singleton, Factory, Module, Decorator, Command, and Observer patterns. It provides descriptions and code examples for each pattern. The Singleton pattern ensures a class only has one instance and provides a global access point. Factory patterns are used for object creation. The Module pattern provides private and public encapsulation for classes. The Decorator pattern attaches additional responsibilities to objects dynamically. The Command pattern encapsulates requests as objects, and the Observer pattern allows objects to watch other objects for changes.

javascriptdesign pattern
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript

1. The document discusses JavaScript concepts like scope, closures, context, and object-oriented programming techniques like constructors, methods, and inheritance. 2. It provides examples of how to create public and private methods, and "privileged" methods that have access to private values and methods. 3. The document shows how to dynamically generate classes at runtime based on properties passed to a constructor using these JavaScript concepts.

contextclosuresscope
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript

Anonymous functions allow functions to be defined and called without a name. JavaScript functions are first-class objects that can be treated like any other object. This allows functions to be defined anonymously and immediately called by wrapping the function definition in parentheses and adding another set of parentheses to call it. For example, (function(){ return "Hello World"; })(); defines and immediately calls an anonymous function without needing to assign it a name.

functionanonymousanonymous function
JavaScript Best Practices
7 – Append an array to another array`
var array1 = [12 , "foo" , {name "Joe"} , -2458];
var array2 = ["Doe" , 555 , 100];
Array.prototype.push.apply(array1, array2);
/* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
8 – Transform the arguments object into an array
var argArray = Array.prototype.slice.call(arguments);
9 – Verify that a given argument is a number
function isNumber(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}
10 – Verify that a given argument is an array
function isArray(obj){
return Object.prototype.toString.call(obj) === '[object Array]' ;
}
JavaScript Best Practices
7 – Append an array to another array
var array1 = [12 , "foo" , {name "Joe"} , -2458];
var array2 = ["Doe" , 555 , 100];
Array.prototype.push.apply(array1, array2);
/* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
8 – Transform the arguments object into an array
var argArray = Array.prototype.slice.call(arguments);
9 – Verify that a given argument is a number
function isNumber(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}
10 – Verify that a given argument is an array
function isArray(obj){
return Object.prototype.toString.call(obj) === '[object Array]' ;
}
11 – Don’t use delete to remove an item from array
Use splice instead of using delete to delete an item from an array. Using delete replaces
the item with undefined instead of the removing it from the array.
Dragos Ionita
Software Engineer
https://ro.linkedin.com/in/dragos-ionita-8ab20756
Dragos Ionita
Software Engineer
https://ro.linkedin.com/in/dragos-ionita-8ab20756
Thanks for watching!Thanks for watching!

More Related Content

What's hot

Bottom Up
Bottom UpBottom Up
Bottom Up
Brian Moschel
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
Brian Moschel
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
Doris Chen
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
Colin DeCarlo
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Nascenia IT
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
Vikas Thange
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Jussi Pohjolainen
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
Pham Huy Tung
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Donald Sipe
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
Mohammed Sazid Al Rashid
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
Derek Brown
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
Tarek Yehia
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
Robert Nyman
 

What's hot (20)

Bottom Up
Bottom UpBottom Up
Bottom Up
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 

Viewers also liked

Web Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User ExperienceWeb Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User Experience
ChromeInfo Technologies
 
vExpert 2014 Certificate by Nathan Gusti Ryan
vExpert 2014 Certificate by Nathan Gusti RyanvExpert 2014 Certificate by Nathan Gusti Ryan
vExpert 2014 Certificate by Nathan Gusti Ryan
Nathan Gusti Ryan
 
Cross Functional Alignment Around the Customer Processes to Drive Success
Cross Functional Alignment Around the Customer Processes to Drive SuccessCross Functional Alignment Around the Customer Processes to Drive Success
Cross Functional Alignment Around the Customer Processes to Drive Success
Gainsight
 
vExpert 2015 Certificate by Nathan Gusti Ryan
vExpert 2015 Certificate by Nathan Gusti RyanvExpert 2015 Certificate by Nathan Gusti Ryan
vExpert 2015 Certificate by Nathan Gusti Ryan
Nathan Gusti Ryan
 
Jose celi
Jose celiJose celi
Jose celi
joseceli1999
 
Grow Smart Program Outline
Grow Smart Program OutlineGrow Smart Program Outline
Grow Smart Program Outline
Ervin Gruia
 
Thames valley prevention powerpoint n.1 v2
Thames valley prevention powerpoint n.1 v2Thames valley prevention powerpoint n.1 v2
Thames valley prevention powerpoint n.1 v2
James Carter
 
Creative designer and front end developer - Two faces of the same coin
Creative designer and front end developer - Two faces of the same coinCreative designer and front end developer - Two faces of the same coin
Creative designer and front end developer - Two faces of the same coin
Web Designers Nepal
 
Ben Brauneck
Ben BrauneckBen Brauneck
Ben Brauneck
Wettbewerb
 
El carnestoltes
El carnestoltesEl carnestoltes
El carnestoltes
gvendre3
 
Del dicho al hecho: analizando proyectos
Del dicho al hecho: analizando proyectosDel dicho al hecho: analizando proyectos
Del dicho al hecho: analizando proyectos
Disonancias
 
Socrative - Gamification in education - Manu Melwin Joy
Socrative - Gamification in education - Manu Melwin JoySocrative - Gamification in education - Manu Melwin Joy
Socrative - Gamification in education - Manu Melwin Joy
manumelwin
 
Tooling for the productive front-end developer
Tooling for the productive front-end developerTooling for the productive front-end developer
Tooling for the productive front-end developer
Maurice De Beijer [MVP]
 
Globalizacion en Ecuador by Diana
Globalizacion en Ecuador by DianaGlobalizacion en Ecuador by Diana
Globalizacion en Ecuador by Diana
diana lozada gonzalez
 
Google Chrome developer tools
Google Chrome developer toolsGoogle Chrome developer tools
Google Chrome developer tools
Daniel Siepmann
 
Smart Sales: entendiendo el proceso de venta
Smart Sales: entendiendo el proceso de ventaSmart Sales: entendiendo el proceso de venta
Smart Sales: entendiendo el proceso de venta
wpargentina
 
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
wpargentina
 

Viewers also liked (17)

Web Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User ExperienceWeb Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User Experience
 
vExpert 2014 Certificate by Nathan Gusti Ryan
vExpert 2014 Certificate by Nathan Gusti RyanvExpert 2014 Certificate by Nathan Gusti Ryan
vExpert 2014 Certificate by Nathan Gusti Ryan
 
Cross Functional Alignment Around the Customer Processes to Drive Success
Cross Functional Alignment Around the Customer Processes to Drive SuccessCross Functional Alignment Around the Customer Processes to Drive Success
Cross Functional Alignment Around the Customer Processes to Drive Success
 
vExpert 2015 Certificate by Nathan Gusti Ryan
vExpert 2015 Certificate by Nathan Gusti RyanvExpert 2015 Certificate by Nathan Gusti Ryan
vExpert 2015 Certificate by Nathan Gusti Ryan
 
Jose celi
Jose celiJose celi
Jose celi
 
Grow Smart Program Outline
Grow Smart Program OutlineGrow Smart Program Outline
Grow Smart Program Outline
 
Thames valley prevention powerpoint n.1 v2
Thames valley prevention powerpoint n.1 v2Thames valley prevention powerpoint n.1 v2
Thames valley prevention powerpoint n.1 v2
 
Creative designer and front end developer - Two faces of the same coin
Creative designer and front end developer - Two faces of the same coinCreative designer and front end developer - Two faces of the same coin
Creative designer and front end developer - Two faces of the same coin
 
Ben Brauneck
Ben BrauneckBen Brauneck
Ben Brauneck
 
El carnestoltes
El carnestoltesEl carnestoltes
El carnestoltes
 
Del dicho al hecho: analizando proyectos
Del dicho al hecho: analizando proyectosDel dicho al hecho: analizando proyectos
Del dicho al hecho: analizando proyectos
 
Socrative - Gamification in education - Manu Melwin Joy
Socrative - Gamification in education - Manu Melwin JoySocrative - Gamification in education - Manu Melwin Joy
Socrative - Gamification in education - Manu Melwin Joy
 
Tooling for the productive front-end developer
Tooling for the productive front-end developerTooling for the productive front-end developer
Tooling for the productive front-end developer
 
Globalizacion en Ecuador by Diana
Globalizacion en Ecuador by DianaGlobalizacion en Ecuador by Diana
Globalizacion en Ecuador by Diana
 
Google Chrome developer tools
Google Chrome developer toolsGoogle Chrome developer tools
Google Chrome developer tools
 
Smart Sales: entendiendo el proceso de venta
Smart Sales: entendiendo el proceso de ventaSmart Sales: entendiendo el proceso de venta
Smart Sales: entendiendo el proceso de venta
 
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
Por qué unirse a la comunidad global de WordPress y cómo ser parte del movimi...
 

Similar to Powerful JavaScript Tips and Best Practices

An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
MD Sayem Ahmed
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
Prajwala Manchikatla
 
Test driven node.js
Test driven node.jsTest driven node.js
Test driven node.js
Jay Harris
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
Robert MacLean
 
Extending javascript part one
Extending javascript part oneExtending javascript part one
Extending javascript part one
Vijaya Anand
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
BoneyGawande
 
Enumerable
EnumerableEnumerable
Enumerable
mussawir20
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
Giovanni Scerra ☃
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
JyothiAmpally
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
Keshav Kumar
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
Keshav Kumar
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
guest4d57e6
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
Demian Holderegger
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
Vincent Pradeilles
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
Dmitry Baranovskiy
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
Universe41
 

Similar to Powerful JavaScript Tips and Best Practices (20)

An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
 
Test driven node.js
Test driven node.jsTest driven node.js
Test driven node.js
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
Extending javascript part one
Extending javascript part oneExtending javascript part one
Extending javascript part one
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Enumerable
EnumerableEnumerable
Enumerable
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
Basics of Javascript
Basics of JavascriptBasics of Javascript
Basics of Javascript
 

More from Dragos Ionita

Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
Dragos Ionita
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
Dragos Ionita
 
The new way to write a frontend software
The new way to write a frontend softwareThe new way to write a frontend software
The new way to write a frontend software
Dragos Ionita
 
Robotics and Arduino (Arduino UNO)
Robotics and Arduino (Arduino UNO)Robotics and Arduino (Arduino UNO)
Robotics and Arduino (Arduino UNO)
Dragos Ionita
 
Html5 - Awesome APIs
Html5 - Awesome APIsHtml5 - Awesome APIs
Html5 - Awesome APIs
Dragos Ionita
 
Hybrid Mobile Application with Ionic Framework
Hybrid Mobile Application with Ionic FrameworkHybrid Mobile Application with Ionic Framework
Hybrid Mobile Application with Ionic Framework
Dragos Ionita
 
Google Tag Manager (GTM)
Google Tag Manager (GTM)Google Tag Manager (GTM)
Google Tag Manager (GTM)
Dragos Ionita
 

More from Dragos Ionita (7)

Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
 
The new way to write a frontend software
The new way to write a frontend softwareThe new way to write a frontend software
The new way to write a frontend software
 
Robotics and Arduino (Arduino UNO)
Robotics and Arduino (Arduino UNO)Robotics and Arduino (Arduino UNO)
Robotics and Arduino (Arduino UNO)
 
Html5 - Awesome APIs
Html5 - Awesome APIsHtml5 - Awesome APIs
Html5 - Awesome APIs
 
Hybrid Mobile Application with Ionic Framework
Hybrid Mobile Application with Ionic FrameworkHybrid Mobile Application with Ionic Framework
Hybrid Mobile Application with Ionic Framework
 
Google Tag Manager (GTM)
Google Tag Manager (GTM)Google Tag Manager (GTM)
Google Tag Manager (GTM)
 

Recently uploaded

論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
Toru Tamaki
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
RaminGhanbari2
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
SynapseIndia
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
rajancomputerfbd
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 

Recently uploaded (20)

論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 

Powerful JavaScript Tips and Best Practices

  • 1. Powerful JavaScript TipsPowerful JavaScript Tips Techniques that all JavaScript programmers can use now you needn’t be an advanced JavaScript developer to benefit from these tips
  • 2. Powerful JavaScript TipsPowerful JavaScript Tips 1. “short circuting” method To set default values, instead of this: function fileName(name) ​ if (!name) { name = "unknown_name"; } return name; } Use this: function fileName(name) name = name || "unknown_name"; return name; }
  • 3. Powerful JavaScript TipsPowerful JavaScript Tips 2. “short circuting” with && (AND) Instead of this: function isAdult(age) { if (age && age > 17) { return true; } ​else { return false; } } Use this: function isAdult(age) { return age && age > 17 ; }
  • 4. Powerful JavaScript TipsPowerful JavaScript Tips 3. It gets more exciting! Instead of this: if (userName) { logIn(userName); } else { signUp(); } Use this: userName && logIn (userName) || signUp ();
  • 5. Powerful JavaScript TipsPowerful JavaScript Tips 4. powerful uses of immediately invoked function expressions Immediately and after invoke (showName = function (name) { console.log(name || "No Name") }) (); // No Name​ ​ showName ("Mike"); // Mike
  • 6. Powerful JavaScript TipsPowerful JavaScript Tips 5. when to use immediately invoked function expressions? All the code is wrapped in the IIFE​ (function () { ​var firstName = “Dragos”, concatenated = undefined; function init () { doStuff (firstName); // code to start the application​ } ​ ​function doStuff (firstName) { concatenated = firstName + 'Developer'; doMoreStuff(); } ​ ​function doMoreStuff () { console.log('Concatenated = ', concatenated; } ​ ​// Start the application init (); }) ();
  • 8. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time.
  • 9. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time. 2 – use === instead of ==
  • 10. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time. 2 – use === instead of == 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy.
  • 11. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time. 2 – use === instead of == 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy. 4 – Be careful when using typeof, instanceof and constructor. typeof : a JavaScript unary operator used to return a string that represents the primitive type of a variable, don’t forget that typeof null will return “object”, and for the majority of object types (Array, Date, and others) will return also “object”. constructor : is a property of the internal prototype property, which could be overridden by code. instanceof : is another JavaScript operator that check in all the prototypes chain the constructor it returns true if it’s found and false if not.
  • 12. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time. 2 – use === instead of == 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy. 4 – Be careful when using typeof, instanceof and constructor. typeof : a JavaScript unary operator used to return a string that represents the primitive type of a variable, don’t forget that typeof null will return “object”, and for the majority of object types (Array, Date, and others) will return also “object”. constructor : is a property of the internal prototype property, which could be overridden by code. instanceof : is another JavaScript operator that check in all the prototypes chain the constructor it returns true if it’s found and false if not. 5 – Get a random item from an array 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy. var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119]; var randomItem = items[Math.floor(Math.random() * items.length)];
  • 13. JavaScript Best Practices 1 – Don’t forget var keyword when assigning a variable’s value for the first time. 2 – use === instead of == 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy. 4 – Be careful when using typeof, instanceof and constructor. typeof : a JavaScript unary operator used to return a string that represents the primitive type of a variable, don’t forget that typeof null will return “object”, and for the majority of object types (Array, Date, and others) will return also “object”. constructor : is a property of the internal prototype property, which could be overridden by code. instanceof : is another JavaScript operator that check in all the prototypes chain the constructor it returns true if it’s found and false if not. 5 – Get a random item from an array 3 – undefined, null, 0, false, NaN, '' (empty string) are all falsy. var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119]; var randomItem = items[Math.floor(Math.random() * items.length)]; 6 – Generate an array of numbers with numbers from 0 to max var numbersArray = [] , max = 100; for( var i=1; numbersArray.push(i++) < max;); // numbers = [1,2,3 ... 100]
  • 14. JavaScript Best Practices 7 – Append an array to another array var array1 = [12 , "foo" , {name "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */
  • 15. JavaScript Best Practices 7 – Append an array to another array` var array1 = [12 , "foo" , {name "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */ 8 – Transform the arguments object into an array var argArray = Array.prototype.slice.call(arguments);
  • 16. JavaScript Best Practices 7 – Append an array to another array` var array1 = [12 , "foo" , {name "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */ 8 – Transform the arguments object into an array var argArray = Array.prototype.slice.call(arguments); 9 – Verify that a given argument is a number function isNumber(n){ return !isNaN(parseFloat(n)) && isFinite(n); }
  • 17. JavaScript Best Practices 7 – Append an array to another array` var array1 = [12 , "foo" , {name "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */ 8 – Transform the arguments object into an array var argArray = Array.prototype.slice.call(arguments); 9 – Verify that a given argument is a number function isNumber(n){ return !isNaN(parseFloat(n)) && isFinite(n); } 10 – Verify that a given argument is an array function isArray(obj){ return Object.prototype.toString.call(obj) === '[object Array]' ; }
  • 18. JavaScript Best Practices 7 – Append an array to another array var array1 = [12 , "foo" , {name "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */ 8 – Transform the arguments object into an array var argArray = Array.prototype.slice.call(arguments); 9 – Verify that a given argument is a number function isNumber(n){ return !isNaN(parseFloat(n)) && isFinite(n); } 10 – Verify that a given argument is an array function isArray(obj){ return Object.prototype.toString.call(obj) === '[object Array]' ; } 11 – Don’t use delete to remove an item from array Use splice instead of using delete to delete an item from an array. Using delete replaces the item with undefined instead of the removing it from the array.
  • 19. Dragos Ionita Software Engineer https://ro.linkedin.com/in/dragos-ionita-8ab20756 Dragos Ionita Software Engineer https://ro.linkedin.com/in/dragos-ionita-8ab20756 Thanks for watching!Thanks for watching!