This is my code:
const a = function(obj) { for (let key in obj) { if (!obj.hasOwnProperty(key)) { continue; } console.info(key.split('_')); } }; a({a_b: 123});
I thought there were no problems, but SonarQube gives a critical error:
TypeError can be selected as a "key" can be null or undefined here.
Highlighted word in key.split ('_') . The specified variable key may be undefined / null here.
I tried passing something like {[undefined]: 123} , and the key variable will become the string "undefined" instead of the real undefined.
Hence. I am wondering if the key will be undefined / null in any possible situation? Or is it just falsely positive?
Here is a screenshot:

source share