Below is the provided code snippet:
var myObject = {
x: 5,
h: function(){
varOne = 2*2;
varTwo = 3*2;
varThree = varOne*varTwo;
},
d: 4
};
var g = myObject.h();
var xyz = g;
var abc = 2;
var efg = 3;
var somearray = [xyz,abc,efg];
var z = 0;
for(i=0; i<somearray.length; i++){
z += somearray[i];
}
The output is NaN. What could be the reason behind this? If I modify it to: h: function(){return 2*2;}, then there are no issues. As a newcomer to JS, I've been researching online for answers without success. Would using parseInt or parseFloat help in this scenario and if so, which variable would require it? Appreciate your assistance.