javascript - What happens if you set a declared variable to a different type? -


var foo = 4; foo = "string" 

what happen here?

foo gets new value, "string". javascript loosely-typed language, variables (and object properties) not restricted holding single type of value during lifecycle.

gratuitous example:

var foo = 42;  snippet.log(typeof foo); // "number"  foo = "the question of life, universe, , everything";  snippet.log(typeof foo); // "string"
<!-- script provides `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->  <script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -