0

When declaring multiple variables in JavaScript, what are the data type restrictions?

var name = "John",
    letter = 'J',
    pi = 3.14,
    hasCar = true,
    license = [6,8,2,7,9,1,5],           
    car = {type:"Fiat", model:"500", color:"white"};

A similar question was asked, but doesn't provide a full answer:

Declaring Multiple Variables in JavaScript

Community
  • 1
  • 1
Alexander
  • 682
  • 1
  • 9
  • 23
  • there are no type restriction, you can declare variable to be whatever value you want, also you can change the value after declaration to whatever different value you want. In javascript variables don't have type only values have. – jcubic Jul 20 '16 at 08:15
  • There are none. Why should there be? JavaScript is dynamically typed. – str Jul 20 '16 at 08:15
  • Even though the above comments are true, in ES6 depending on if the variable will change value you might want to use let/const, so that might be a "restriction" in some sense.. see: https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75#.l34nm6slx – Cisum Inas Jul 20 '16 at 08:16

3 Answers3

0

You can declare many variables in one statement. See it here

vtking
  • 43
  • 2
  • 12
0

JavaScript is a dynamic language. That means you don't have to declare the type of a variable. The type will be determined automatically while the program is being processed. That also means that you can have the same variable as different types.

You can see all data types in the link below:

Data Types JavaScript

Mikel
  • 165
  • 14
0

I suppose this first link will explain you the declaration of the variable as well as multiple. This second link could help you understand the different data types declarations.

You can also take a look at these two links which are explaining multiple declaration of variables in java Script. Third link Fourth link

ReshaD
  • 906
  • 15
  • 29