{"id":4,"date":"2007-10-25T16:46:15","date_gmt":"2007-10-25T23:46:15","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=4"},"modified":"2011-05-06T07:21:14","modified_gmt":"2011-05-06T07:21:14","slug":"javascript-variables","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2007\/10\/25\/javascript-variables\/","title":{"rendered":"Javascript Variables"},"content":{"rendered":"<p>Remember, Javascript is not a strongly typed language. While using variables in Javascript, don\u2019t bother about the type of data a variable is storing, instead what the variable is storing. These variables can store anything &#8211; even functions!! Here are some examples on using variables in Javascript.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var thisIsAString = 'This is a string';\r\nvar alsoAString = '25';\r\nvar isANumber = 25;\r\nvar isEqual = (alsoAString==isANumber);  \/\/ This is true, they are both 25.\r\nvar isEqual = (alsoAString===isANumber); \/\/ False one is a number,\r\n                                         \/\/ the other a string.\r\n\r\nvar concat=alsoAString + isANumber;      \/\/ concat is now 2525\r\nvar addition=isANumber + isANumber;      \/\/ addition is now 50\r\nvar alsoANumber=3.05;     \/\/ is equal to 3.05 (usually).\r\nvar floatError=0.06+0.01; \/\/ is equal to 0.06999999999999999\r\nvar anExponent=1.23e+3;   \/\/ is equal to 1230\r\n\r\nvar hexadecimal = 0xff;   \/\/ is equal to 255.\r\nvar octal = 0377;         \/\/ is equal to 255.\r\n\r\nvar isTrue = true;   \/\/ This is a boolean, it can be true or false.\r\nvar isFalse= false;  \/\/ This is a boolean, it can be true or false\r\n\r\nvar isArray = [0, 'one', 2, 3, '4', 5]; \/\/ This is an array.\r\nvar four = isArray[4]; \/\/ assign a single array element to a variable.\r\n                       \/\/ in this case four = '4'\r\n\r\nvar isObject = { 'color': 'blue',  \/\/ This is a Javascript object\r\n                 'dog': 'bark',\r\n                 'array': [0,1,2,3,4,5],\r\n                 'myfunc': function () { alert('do something!'); }\r\n               }\r\n\r\nvar dog = isObject.dog;  \/\/ dog now stores the string 'bark';\r\nisObject.myfunc();       \/\/ creates an alert box with the value &quot;do something!&quot;\r\nvar someFunction = function() {\r\n                      return &quot;I am a function!&quot;;\r\n}\r\nvar alsoAFunction = someFunction; \/\/No () so alsoAFunction becomes a function\r\nvar result = alsoAFunction(); \/\/ alsoAFunction is executed here because ()\r\n                              \/\/ executes the function so result stores the\r\n                              \/\/ return value of the function which is\r\n                              \/\/ &quot;I am a function!&quot;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Remember, Javascript is not a strongly typed language. While using variables in Javascript, don\u2019t bother about the type of data a variable is storing, instead what the variable is storing. These variables can store anything &#8211; even functions!! Here are some examples on using variables in Javascript.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/4"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=4"}],"version-history":[{"count":2,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":185,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/4\/revisions\/185"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}