SlideShare a Scribd company logo
1 of 17
Airbnb JavaScript Style Guide() {
Code is first for
human…
not computer
“
Why
Style Guide?
Best practices.
More readable code
Easy maintenance
Single standard?
No, like a lot
• Airbnb
• Google
• JQuery
• W3Schools
• Node
• StandardJS
● We focus on Airbnb
References
● Use const or let for all of your
references - avoid using var
● const and let only exist in the
blocks they are defined in
● var is a function-scoped
● Use one const or let declaration
per variable
● Don't chain variable assignments
● Avoid using ++, --
Variables
● Literal syntax for object creation
● Don't use reserved words as keys
● Use object method shorthand
● Use property value shorthand
● Group your shorthand properties
at the beginning of your object
declaration.
Objects
● Use the literal syntax for array
creation
● Use Array#push instead of direct
assignment to add items to an
array
● Use spread operator ... to copy
arrays
Arrays
● Use single quotes '' for strings.
● Strings that cause the line to go
over 100 characters should not be
wrapped by concatenation
● When building up strings, use
template instead of concatenation
● Do not unnecessarily escape
characters in strings as
backslashes harm readability
Strings
Almost there...
● Use named function expressions
instead of function declarations
Function declarations are hoisted -- easy to use
before it is defined in the file -- harms
readability and maintainability
● Name the expression
● Wrap immediately invoked
function expressions in
parentheses
● Use default parameter syntax
rather than mutating function
arguments
Functions
● Put default parameters last
● Spacing in a function signature
● Never mutate parameters
● Never reassign parameters
● Multiline signatures should:
○ each item on a line by itself
○ trailing comma on the last
item
Functions
● Use === and !== over
== and !=
● Use shortcuts for booleans, but
explicit comparisons for strings
and numbers
● Ternaries should not be nested
and generally be single line
expressions
● Avoid unneeded ternary
statements
Comparison &
Equality
● Don't use iterators
● Prefer higher-order functions
map() / every() / filter() / …
and
Object.keys() / Object.values() / ...
over loops like for-in, as this
enforces immutability
Iterators
● Always comma-dangle (cleaner
diff), even in function definition
● /** ... */ multi-line comments
● // for single line comments
● // FIXME: to annotate problems
● // TODO: to annotate solutions
Commas,
Comments
Guidelines use of EcmaScript 2015
features
Modules import/export
Class & extends
String template notation
Arrow functions
Furthermore...
Linters
ESlint - Airbnb Style .eslintrc
JSHint - Airbnb Style .jshintrc
JSCS - Airbnb Style Preset
CSS
Airbnb CSS / Sass Styleguide
References
● https://github.com/airbnb/javascript

More Related Content

Similar to Airbnb Javascript Style Guide

JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2Chris Farrell
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixirkirandanduprolu
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1Mukesh Kumar
 
Perl Best Practices Reference Guide version 1.01.00
Perl Best Practices Reference Guide version 1.01.00Perl Best Practices Reference Guide version 1.01.00
Perl Best Practices Reference Guide version 1.01.00ego2
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scaladatamantra
 
Part 2 in depth guide on word-press coding standards for css & js big
Part 2  in depth guide on word-press coding standards for css & js bigPart 2  in depth guide on word-press coding standards for css & js big
Part 2 in depth guide on word-press coding standards for css & js bigeSparkBiz
 
Airbnb Java Script style guide
Airbnb Java Script style guideAirbnb Java Script style guide
Airbnb Java Script style guideAhmed Elbassel
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in RubyAlex Teut
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool LabsHarutyun Abgaryan
 
Best Coding Practices in Java and C++
Best Coding Practices in Java and C++Best Coding Practices in Java and C++
Best Coding Practices in Java and C++Nitin Aggarwal
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to javaSadhanaParameswaran
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptxSrizan Pokrel
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_scriptVijay Kalyan
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)Shoaib Ghachi
 
Programming in python - Week 2
Programming in python - Week 2Programming in python - Week 2
Programming in python - Week 2Priya Nayak
 
CodingStandardsDoc
CodingStandardsDocCodingStandardsDoc
CodingStandardsDocAmol Patole
 
JavaScript Introductin to Functions
JavaScript Introductin to FunctionsJavaScript Introductin to Functions
JavaScript Introductin to FunctionsCharles Russell
 

Similar to Airbnb Javascript Style Guide (20)

JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixir
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
Perl Best Practices Reference Guide version 1.01.00
Perl Best Practices Reference Guide version 1.01.00Perl Best Practices Reference Guide version 1.01.00
Perl Best Practices Reference Guide version 1.01.00
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Part 2 in depth guide on word-press coding standards for css & js big
Part 2  in depth guide on word-press coding standards for css & js bigPart 2  in depth guide on word-press coding standards for css & js big
Part 2 in depth guide on word-press coding standards for css & js big
 
Airbnb Java Script style guide
Airbnb Java Script style guideAirbnb Java Script style guide
Airbnb Java Script style guide
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool Labs
 
Best Coding Practices in Java and C++
Best Coding Practices in Java and C++Best Coding Practices in Java and C++
Best Coding Practices in Java and C++
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Learning core java
Learning core javaLearning core java
Learning core java
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Programming in python - Week 2
Programming in python - Week 2Programming in python - Week 2
Programming in python - Week 2
 
CodingStandardsDoc
CodingStandardsDocCodingStandardsDoc
CodingStandardsDoc
 
JavaScript Introductin to Functions
JavaScript Introductin to FunctionsJavaScript Introductin to Functions
JavaScript Introductin to Functions
 
C tour Unix
C tour UnixC tour Unix
C tour Unix
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Airbnb Javascript Style Guide

  • 2. Code is first for human… not computer “
  • 3. Why Style Guide? Best practices. More readable code Easy maintenance
  • 4. Single standard? No, like a lot • Airbnb • Google • JQuery • W3Schools • Node • StandardJS ● We focus on Airbnb
  • 5. References ● Use const or let for all of your references - avoid using var ● const and let only exist in the blocks they are defined in ● var is a function-scoped
  • 6. ● Use one const or let declaration per variable ● Don't chain variable assignments ● Avoid using ++, -- Variables
  • 7. ● Literal syntax for object creation ● Don't use reserved words as keys ● Use object method shorthand ● Use property value shorthand ● Group your shorthand properties at the beginning of your object declaration. Objects
  • 8. ● Use the literal syntax for array creation ● Use Array#push instead of direct assignment to add items to an array ● Use spread operator ... to copy arrays Arrays
  • 9. ● Use single quotes '' for strings. ● Strings that cause the line to go over 100 characters should not be wrapped by concatenation ● When building up strings, use template instead of concatenation ● Do not unnecessarily escape characters in strings as backslashes harm readability Strings
  • 11. ● Use named function expressions instead of function declarations Function declarations are hoisted -- easy to use before it is defined in the file -- harms readability and maintainability ● Name the expression ● Wrap immediately invoked function expressions in parentheses ● Use default parameter syntax rather than mutating function arguments Functions
  • 12. ● Put default parameters last ● Spacing in a function signature ● Never mutate parameters ● Never reassign parameters ● Multiline signatures should: ○ each item on a line by itself ○ trailing comma on the last item Functions
  • 13. ● Use === and !== over == and != ● Use shortcuts for booleans, but explicit comparisons for strings and numbers ● Ternaries should not be nested and generally be single line expressions ● Avoid unneeded ternary statements Comparison & Equality
  • 14. ● Don't use iterators ● Prefer higher-order functions map() / every() / filter() / … and Object.keys() / Object.values() / ... over loops like for-in, as this enforces immutability Iterators
  • 15. ● Always comma-dangle (cleaner diff), even in function definition ● /** ... */ multi-line comments ● // for single line comments ● // FIXME: to annotate problems ● // TODO: to annotate solutions Commas, Comments
  • 16. Guidelines use of EcmaScript 2015 features Modules import/export Class & extends String template notation Arrow functions Furthermore... Linters ESlint - Airbnb Style .eslintrc JSHint - Airbnb Style .jshintrc JSCS - Airbnb Style Preset CSS Airbnb CSS / Sass Styleguide