Kayote Kayote - 1 year ago 102
Javascript Question

Argument of Different Data-Types

Is it a good idea / practice to do the following:

export const checkAndUpdateCredit = ( total, addback = false ) => {
// here, addback can be an obj or boolean
let value = total - addback.value

As per the comment, if the argument of
isn't passed, it defaults to
, else an object is required to be passed. Here a single parameter can be either an
or a
. Is this a good practice / acceptable?

Answer Source

You could use a default value inside of addback

export const checkAndUpdateCredit = (total, addback = { value: 0 }) => {
//                                                    ^^^^^^^^^^^^
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download