Today I Learned - Rocky Kev

TIL a easier way to check for multiple OR statements

POSTED ON:

TAGS:

I nerd out about this stuff.

Essentially, it's turning a multiple conditional into a array, then array to see if it matches.

// longhand
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
//logic
}

//shorthand
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
//logic
}

via Blessing Hirwa


Related TILs

Tagged:

TIL a easier way to check for multiple OR statements

Essentially, it's turning a multiple conditional into a array, then array to see if it matches.

TIL a easier way to check for multiple OR statements

Essentially, it's turning a multiple conditional into a array, then array to see if it matches.

TIL a easier way to check for multiple OR statements

Essentially, it's turning a multiple conditional into a array, then array to see if it matches.