Consider the followng code
<!DOCTYPE html>
<html>
<head>
<script>
var name = 0;
while ( name < 6 ) {
console.log('Masha');
name = name + 1;
console.log(name);
}
</script>
</head>
<body>
</body>
</html>
I expect the output in Chrome Developer Tools to be:
Masha
name.html:9 1
name.html:7 Masha
name.html:9 2
name.html:7 Masha
name.html:9 3
name.html:7 Masha
name.html:9 4
name.html:7 Masha
name.html:9 5
name.html:7 Masha
name.html:9 6
Instead I get
Masha
name.html:9 01
name.html:7 Masha
name.html:9 011
Why is this the case? It also happens if I copy/paste the code directly. If I chop the n
of of name
then it does work. If I change the variable to myName
it does work. Why is it coerced to a string? I'm using Version 57.0.2987.133 (64-bit)
of Chrome. It also happens in Firefox 52.0.2 (64-bits)
.
This doesn't happen when I run the code in node or in Internet Explorer.