javascript - Why will this Js function return undefined? -


my goal pass in variable apply many processes within function, rule im unaware of must coming play. return passed variable, not return full object including variable parent...

var test = {number:1,color:'red'}; function make(data){     console.log(data)        //returns test     console.log(test.number) //returns 1     console.log(data,test.number) //returns test 1     console.log(data.number) //returns undefined }; make("test"); 

you calling string has no property number should call test object instead

var test = {number:1,color:'red'};  function make(data){      console.log(data)        //returns test      console.log(test.number) //returns 1      console.log(data,test.number) //returns test 1      console.log(data.number) //returns 1  };  make(test);


Comments

Popular posts from this blog

php - Embed BBCode within itself not working -

three.js - how to load gltf in three JS -

sql server - T-SQL: Access DB objects in same schema without qualifying? -