0
I want to know why it works to change but not to create
    var obj = {};
    
    obj.teste = {id:1}; //esse funciona para criar
    
    obj.teste.id = 2; //e assim eu altero
    
    console.log(JSON.stringify(obj)); 
    
    
    var obj2 = {};
    obj2.teste2.id = 1; //isso não funciona, e pra mim faria sentido que o js criasse um obj com o id, mas ele da erro Cannot set property 'id' of undefined
    
    onsole.log(JSON.stringify(obj2));I want to understand the point where my intuition says example 2 should work, but it doesn’t work.
How come it doesn’t work to create? What exactly are you trying to do?
– Sorack
edited the publication
– cpll