javascript varaibles code example

Example 1: varianle in javascript

var one = 1; // variable stores numeric value

var two = 'two';  // variable stores string value

var three;  // declared a variable without assigning a value

Example 2: how to define variable in javascript

var <variable-name>;

var <variable-name> = <value>;

Example 3: varaible javascript

let <var-name> = value;

Example 4: how to make a variable equal a specific element in javascript

//How to make a variable equal a specific element in javascript.

/*====DESCRIPTION STARTS HERE=======
Assuming you've already created an array and a variable, you simply set the
variable equal to the array, specifying the specific location of the value
it holds. Note though that when specifying the location, subtract one
number from the actual number we percieve. The reason for this is that computers
begin counting at 0.
  =====DESCRIPTION ENDS HERE========*/

//=====EXAMPLE=========
var listOfFirstNames = ["Will", "Kotori", "Grace", "James"]
var FirstName = listOfFirstNames[2] /*firstName now has the value of "Grace"
									since grace is the 2nd (or 3rd) element
									of the array*/

Tags:

Html Example