Write beautiful and Elegant Javascript code with short-circuit evaluation.

let length = 0
if Array.isArray(arr) {
length = arr.length
}
let length = (arr || []).length
  • logical AND (&&)
  • logical OR (||)
  • logical NOT (!)

Return the first expression evaluated to false

50 && true && 1 && false // Return: false
1 && 0 // Return: 0
5 && 6 && true && 100  // Return: 100

Return the first expression evaluated to true

0 || false || 10 // return: 10
message = 'There is no information available'
if (website.data) {
message = website.data
}
message = website.data || "There is no information available"

--

--

--

Remote software engineer eager to become a programming artist.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Node JS Error Handling: How and Why Bother?

From Native to JavaScript and back or trigger native components in React Native

Create a generic dropdown using Bootstrap, Angular and RxJS!

Why we REALLY need to stop using switch statements in JavaScript

Lazy loading feature of Code Splitting technique in React

Convert A Svelte Project from Rollup to Snowpack and Enjoy Instant Page Updates and HMR

Kanji made easy#1

Single Page Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HoraceFayomi

HoraceFayomi

Remote software engineer eager to become a programming artist.

More from Medium

Introduction to JavaScript

Javascript, Undefined vs null

Understanding JavaScript's ‘this’ keyword

8 Must Know Javascript Array Methods