I'm learning JS and quite confused about variables:
Short Story: How browsers determine the type of data under var tag, how they determine storage requirements for the type of data under var tag, what happens when two different types of data are assigned one-after-another to the same variable and why these variables're all warped up under var name? It would make more sense if JS had different types of data as integers, strings etc.
Long Story: Normally, when we want to declare a variable, we define its type: integer, string or char etc. This way, we make sure enough storage is allocated for variable and most of the time, there're some special functions for that specific variable type. In JS, variables -and apparently functions too- are simply used under var name. So, we store anything under var name. My question is this: how browsers/JS compilers differentiate types of data in variables as string/char etc, how they decide the bit-length required for that data, and how they handle which functions will suit that data? What happens when I assign an integer to that variable first, then a string later? Also, wouldn't it be easier to define different types of variables?
I'm a beginner on JS, so go easy on me please. Cheers!