1

Must you define a data type when declaring a variable in JavaScript?

4
  • No, you can define variables in javascript like var myVariable Commented Feb 26, 2017 at 4:25
  • to say "you can" suggests there's another option - there isn't ... variables are untyped Commented Feb 26, 2017 at 4:31
  • @jaromandaX Good point, you MUST declare variables with the var keyword, but is now too late to edit my comment Commented Feb 26, 2017 at 4:33
  • of course, there's var, let and const now :p and not using any of those is equivalent to window.xxx (in a browser) Commented Feb 26, 2017 at 4:34

3 Answers 3

0

No, you ca go with just

var x = 5;

The interpreter would guess what type the var is.

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

Comments

0

No. Javascript is not strongly typed.

Comments

0

No, in Javascript variables are defined by simply using the var keyword followed by your variable name.

Example

var intVariable = 3;

var stringVariable = "Dog";

You can read more about javascript variables here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.