I have created REST API using node.js.since the API consumer is not correctly populating the object & some of the object attributes are coming "undefined" and sometimes undefined.
I have added a request interceptor that rejects API request if the required request parameters are missing
this is how my code looks like today. I just want to check if there is any better way to handle it.
(!variable_name || variable_name === 'undefined')
'undefined'instead ofundefined!variablemeans it could be 0, empty string, undefined, null (and I'm probably forgetting others). you can check for exact equality to undefined by sayingfoo === undefined. note the three equals. the string 'undefined' is just a word, you may as well have said 'bar' there.||instead of!!I am doing likeand getting a syntax error in the console no doubtwindowin an unknown context. If you know you have a variable available,typeofis not necessary.