Stop using nested ifs. Do this instead

Tari Ibaba
Coding Beauty
Published in
6 min readApr 3, 2023

--

A typical use case for nested ifs: you want to perform all sorts of checks on some data to make sure it’s valid before finally doing something useful with it.

Don’t do this! :

// JavaScript

function sendMoney(account, amount) {
if (account.balance > amount) {
if (amount > 0) {
if (account.sender === 'user-token') {
account.balance -= amount…

--

--

Tari Ibaba
Coding Beauty

I help you gain the coding knowledge and skills to build the life you love.