SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
7
Javascript Hacks for Hipsters
/Tal Bereznitskey @ketacode
Hipster Hack #1 - Method
calling
Trade bloated if/else blocks for a quick function call
//Boring
if(success){
obj.start();
}else{
obj.stop();
}
//Hipster-fun
varmethod=(success?'start':'stop');
obj[method]();
Hipster Hack #2 - String joins
Concatenate two strings or more simpler, easier and faster
['first','name'].join('');//='firstname';
['milk','coffee','sugar'].join(',');//='milk,coffee,sugar'
Hipster Hack #3 - Default
Operator ||
Use the || operator to use the second argument if the first is falsy
//defaultto'Noname'whenmyNameisempty(ornull,orundefined)
varname=myName||'Noname';
//makesurewehaveanoptionsobject
vardoStuff=function(options){
options=options||{};
//...
};
Hipster Hack #4 - Guard
Operator &&
Use the && operator to eliminate almost all IF calls and make your code
nicers
//Boring
if(isThisAwesome){
alert('yes');//it'snot
}
//Awesome
isThisAwesome&&alert('yes');
//Alsocoolforguardingyourcode
varaCoolFunction=undefined;
aCoolFunction&&aCoolFunction();//won'trunnorcrash
Hipster Hack #5 - XXX Operator
Whenever I write some code, but then have to consult the web, or a different part of the code, I add an xxx line to the code.
This makes the code break so I can get back to the specific place and fix it later. Much easier to search for it (xxx usually
never appears) and you don’t have to think about a TODO comment.
varz=15;
doSomeMath(z,10);
xxx//Greatplaceholder.I'mtheonlyoneusingxxxandit'ssoeasytofindincodeinsteadofT
doSomeMoreMath(z,15);
Hipster Hack #6 - Timing
Use the console’s timing methods to test for event-loop blocking code
vara=[1,2,3,4,5,6,7,8,9,10];
console.time('testing_forward');
for(vari=0;i<a.length;i++);
console.timeEnd('testing_forward');
//output:testing_forward:0.041ms
console.time('testing_backwards');
for(vari=a.length-1;i>=0;i--);
console.timeEnd('testing_backwards');
//output:testing_backwards:0.030ms
Hipster Hack #7 - Debugging
Drop a debugger statement and the debugger will stop on that line
varx=1;
debugger;//Codeexecutionstopshere,happydebugging
x++;
varx=Math.random(2);
if(x>0.5){
debugger;//Conditionalbreakpoint
}
x--;
More...
There are 2 more hipster hacks in the full blog post:
Javascript Hacks for Hipsters
Happy Coding
Tal Bereznitskey
Blog: berzniz.com
Twitter: @ketacode

Weitere ähnliche Inhalte

Was ist angesagt?

2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScriptJohannes Hoppe
 
There's a Filter For That
There's a Filter For ThatThere's a Filter For That
There's a Filter For ThatDrewAPicture
 
Class 7a: Functions
Class 7a: FunctionsClass 7a: Functions
Class 7a: FunctionsMarc Gouw
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by examplebryanbibat
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScriptStalin Thangaraj
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming LanguageDuda Dornelles
 
Php radomize
Php radomizePhp radomize
Php radomizedo_aki
 
Background Processing in Ruby on Rails
Background Processing in Ruby on RailsBackground Processing in Ruby on Rails
Background Processing in Ruby on Railsrobmack
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentationadamcookeuk
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015qmmr
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design PatternsDerek Brown
 
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)성일 한
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 

Was ist angesagt? (20)

2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
There's a Filter For That
There's a Filter For ThatThere's a Filter For That
There's a Filter For That
 
Class 7a: Functions
Class 7a: FunctionsClass 7a: Functions
Class 7a: Functions
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Vim Hacks
Vim HacksVim Hacks
Vim Hacks
 
Fancy talk
Fancy talkFancy talk
Fancy talk
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming Language
 
Php radomize
Php radomizePhp radomize
Php radomize
 
Background Processing in Ruby on Rails
Background Processing in Ruby on RailsBackground Processing in Ruby on Rails
Background Processing in Ruby on Rails
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 

Andere mochten auch

Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessibleDirk Ginader
 
AEJMC 2014 - How scientists see engagement goals
AEJMC 2014 - How scientists see engagement goalsAEJMC 2014 - How scientists see engagement goals
AEJMC 2014 - How scientists see engagement goalsJohn C. Besley
 
Goal setting and prioritizing
Goal setting and prioritizingGoal setting and prioritizing
Goal setting and prioritizingIdols287
 
CCI Project Prioritization Project
CCI Project Prioritization ProjectCCI Project Prioritization Project
CCI Project Prioritization Projectjcvpve
 
Smart Goals Presentation
Smart Goals PresentationSmart Goals Presentation
Smart Goals PresentationLisa Dabbs
 
Project Prioritization Tool
Project Prioritization ToolProject Prioritization Tool
Project Prioritization ToolDemand Metric
 
Prioritising almost anything – UXcamp London
Prioritising almost anything – UXcamp LondonPrioritising almost anything – UXcamp London
Prioritising almost anything – UXcamp LondonEva-Lotta Lamm
 
IT Project Tracking and Prioritization - Kickoff
IT Project Tracking and Prioritization - KickoffIT Project Tracking and Prioritization - Kickoff
IT Project Tracking and Prioritization - KickoffMargaret D.
 
The Javascript Toolkit 2.0
The Javascript Toolkit 2.0The Javascript Toolkit 2.0
The Javascript Toolkit 2.0Marcos Vinícius
 
Roadmaps That Inspire
Roadmaps That InspireRoadmaps That Inspire
Roadmaps That InspireUpUp Labs
 
Utilizando recursos de realidade aumentada em aplicações
Utilizando recursos de realidade aumentada em aplicaçõesUtilizando recursos de realidade aumentada em aplicações
Utilizando recursos de realidade aumentada em aplicaçõesPedro Kayatt
 
Lyn pugecte bereket folder
Lyn pugecte  bereket folderLyn pugecte  bereket folder
Lyn pugecte bereket folderbreket
 
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?Pedro Kayatt
 
The Host opening analysis
The Host opening analysisThe Host opening analysis
The Host opening analysisrobynnwardd
 
Stats joueurs
Stats joueursStats joueurs
Stats joueursBD GB
 

Andere mochten auch (19)

Making your Angular.js Application accessible
Making your Angular.js Application accessibleMaking your Angular.js Application accessible
Making your Angular.js Application accessible
 
AEJMC 2014 - How scientists see engagement goals
AEJMC 2014 - How scientists see engagement goalsAEJMC 2014 - How scientists see engagement goals
AEJMC 2014 - How scientists see engagement goals
 
Smart goals
Smart goalsSmart goals
Smart goals
 
Goal setting and prioritizing
Goal setting and prioritizingGoal setting and prioritizing
Goal setting and prioritizing
 
Gartner Report: Aligning Supply and Demand for IT Services
Gartner Report: Aligning Supply and Demand for IT ServicesGartner Report: Aligning Supply and Demand for IT Services
Gartner Report: Aligning Supply and Demand for IT Services
 
CCI Project Prioritization Project
CCI Project Prioritization ProjectCCI Project Prioritization Project
CCI Project Prioritization Project
 
Smart Goals Presentation
Smart Goals PresentationSmart Goals Presentation
Smart Goals Presentation
 
Project Prioritization Tool
Project Prioritization ToolProject Prioritization Tool
Project Prioritization Tool
 
Prioritising almost anything – UXcamp London
Prioritising almost anything – UXcamp LondonPrioritising almost anything – UXcamp London
Prioritising almost anything – UXcamp London
 
IT Project Tracking and Prioritization - Kickoff
IT Project Tracking and Prioritization - KickoffIT Project Tracking and Prioritization - Kickoff
IT Project Tracking and Prioritization - Kickoff
 
Easy Project Prioritization
Easy Project PrioritizationEasy Project Prioritization
Easy Project Prioritization
 
The Javascript Toolkit 2.0
The Javascript Toolkit 2.0The Javascript Toolkit 2.0
The Javascript Toolkit 2.0
 
Roadmaps That Inspire
Roadmaps That InspireRoadmaps That Inspire
Roadmaps That Inspire
 
Utilizando recursos de realidade aumentada em aplicações
Utilizando recursos de realidade aumentada em aplicaçõesUtilizando recursos de realidade aumentada em aplicações
Utilizando recursos de realidade aumentada em aplicações
 
Lyn pugecte bereket folder
Lyn pugecte  bereket folderLyn pugecte  bereket folder
Lyn pugecte bereket folder
 
Audience
AudienceAudience
Audience
 
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?
Realidade Virtual/Aumentada e Mixed Reality. Estamos no Futuro?
 
The Host opening analysis
The Host opening analysisThe Host opening analysis
The Host opening analysis
 
Stats joueurs
Stats joueursStats joueurs
Stats joueurs
 

Kürzlich hochgeladen

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 

Kürzlich hochgeladen (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 

JavaScript Hacks for Hipsters