@RahulArora has basically provided the right answer, but to provide a bit more illumination about what is happening:
Browsers have a built-in global variable called name which stores the name of the window. If you assign a value to it, the value you assign will be converted to a string. This has nothing to do with prompt(); you can observe it like this:
var name = null;
console.log(typeof name); // "string"
console.log(name.length); // 4
The moral of the story: Avoid using global variables unless you absolutely have to, and if you do, make sure they're not already being used for something else!