0

I have just started using JavaScript and it just seems strange to me that when the variable is declared,we don't have to specify the datatype. Is there any specific reason this is done?

2
  • JavaScript doesn't really care about that stuff. var a = "abc";a=5; is valid code Commented Apr 8, 2015 at 4:03
  • JavaScript is not a strictly typed language (at least, yet). Commented Apr 8, 2015 at 4:03

2 Answers 2

1

The reason for this is so dynamic types can be used. Thus, this following code, whose counterpart would be invalid, works:

var x;               // Now x is undefined
var x = 5;           // Now x is a Number
var x = "John";      // Now x is a String

Thus, is not a strictly typed language.

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

Comments

-1

Javascript is a loosely-typed language so variables types are determined at runtime instead of at compile time.

1 Comment

Variables don't have types. Only values do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.