0

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?

1
  • By parsing it you know the data type. The internal representation could be anything. Commented Jun 16, 2017 at 6:51

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

Link-only answers are discouraged. Answers should stand on their own, but may contain links to supporting information.
thankyou for your helpfull suggestions

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.