How can I clean up this if-else function?

I’m a beginner React developer.

I am cleaning up my codes.

I’m trying to get rid of the if-else statement as much as possible, but I don’t know how to handle this function.

    const calc = () => {
        if (width < Number( {
        } else if (width < Number(width.tablet)) {
        } else if (width < Number(width.smallDesktop)) {
        } else if (width < Number(width.desktop)) {
        } else {

I really hate this code.
Can you help me out?

Source: JavaSript – Stack Overflow

November 7, 2021
Category : News
Tags: code-cleanup | if-statement | javascript | reactjs | refactoring

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.