In JavaScript the keyword var
is used to declare a variable. How does the JavaScript Engine parse it and recognize the datatype of that variable?

- 9
- 2
- 5
-
By parsing it you know the data type. The internal representation could be anything. – Dave Newton Jun 16 '17 at 06:51
1 Answers
The variable’s data type is the JavaScript scripting engine’s interpretation of the type of data that variable is currently holding. A string variable holds a string; a number variable holds a number value, and so on. However, unlike many other languages, in JavaScript, the same variable can hold different types of data, all within the same application. This is a concept known by the terms loose typing and dynamic typing, both of which mean that a JavaScript variable can hold different data types at different times depending on context.
With a loosely typed language, you don’t have to declare ahead of time that a variable will be a string or a number or a boolean, as the data type is actually determined while the application is being processed. If you start out with a string variable and then want to use it as a number, that’s perfectly fine, as long as the string actually contains something that resembles a number and not something such as an email address. If you later want to treat it as a string again, that’s fine, too.
you can read this link all about javascript variables and types
I hope it will be helpfull

- 122
- 2
- 12
-
Link-only answers are discouraged. Answers should stand on their own, but may contain links to supporting information. – Dave Newton Jun 16 '17 at 11:17
-