Jump to content

JavaScript Variables

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Hello All,

I'm a newbie to JavaScript (only been doing it for a week) and I was wondering how to make variables.

I've seen some lines of code go like this:

var someVariable () 

Is that a variable?

Also are there different types of variables like in C++ or Java.

Thank You.

#2
kotg2

kotg2

    Newbie

  • Members
  • Pip
  • 4 posts
In Javascript all variables are declared as in your example except without the ().

Javascript is not strongly typed so you do not need to explicitly declare what type of object the variable will refer to.

So if you wanted to declare and initialise an int variable in Javascript you would do the following:

var x = 0;

and if you wanted to declare and intialise a string variable you would use the following code:

var str = "example";

A variable however does not need to be initialised when it is declared and can be reassigned to different type of object at any time.