DEV Community

Discussion on: Javascript Clean Code Tips & Good Practices

Collapse
 
efpage profile image
Eckehard

Nice writeup, thank you very much.

About default arguments it should be mentioned, that the "bad" solution may also cause unexpected errors:

    function getValue(val) {
      const myVal = val || 1;
      console.log(myVal)
    }
    getValue(2) // => 2
    getValue(0) // => 1
Enter fullscreen mode Exit fullscreen mode

val may be empty or zero to get the second argument of ||

Collapse
 
apoorvtyagi profile image
Apoorv Tyagi

Thanks.

yeah that's a good one to know as well๐Ÿ‘