<!DOCTYPE html>

<p>Given that y=5, calculate x=y+2, and display the result.</p>
<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

function myFunction()
var y=5;
var x=y+2;
var demoP=document.getElementById("demo")
demoP.innerHTML="x=" + x;


Can anybody please explain me why on the "demoP.innerHTML="x=" + x;", the function has to be written in "="x=" + x;"? I got this example from w3school, but nobody explains anything about it.
Please help!!