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

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -