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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -