'why can't I insert text object into an element's innerHTML

we can assign the input value to a variable and then we're assingning that variable to an element's innerHTML, likewise why can't I insert text object into an element's innerHTML??

eg code:

x=document.getElementById("my_input"). value;

y=document.createElement("p");

y.innerHTML=x;

This code works but the below code isn't, why?

eg code:

x=document.getElementById("my_input"). value;


y=document.createElement("p");

z=document.createTextNode("x");

y.innerHTML=z;

I'm a beginner in js.. Correct me if I'm wrong..thanks!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source