JS Variables and Use Strict Mode
EasyProgramming.net tutorial on JS Variables and the use of strict mode
by Nazmus Nasir
HTML
<!-- JavaScript Variables and typeof() - #5 -->
<p>
Variables are normally declared by using the keyword 'var' - although it's not necessary, it's recommended so that any webpage which uses "use strict" does not block an undeclared variable. It makes it easier to write "secure" JavaScript. Without 'use strict', you can accidentally declare new global variables, usually by a typo. 'Use Strict' will not allow you to call an undefined variable.
<br />More info at <a href="http://www.w3schools.com/js/js_strict.asp">http://www.w3schools.com/js/js_strict.asp</a>
</p>
<p>
Variables are CASE SENSITIVE! 'car' does not equal to 'CAR'
</p>
<p>
Variables cannot begin with a number! But they can contain numbers and special characters.
</p>
<p>
<code>typeof(x)</code> can be used to find the type of variable something is.
</p>
<div id="title">
<a href="http://www.easyprogramming.net">EasyProgramming.net</a>
</div>
JavaScript
//Strict mode states that all code must be executed in strict mode
//"use strict";
//string - always in quotes - single or double
var car = "Toyota";
console.log(car + " is of type " + typeof(car));
//number
var rent = 1500;
//console.log(rent + " is of type " + typeof(rent));
//object
var phone = {};
//console.log("phone is of type " + typeof(phone));
//array object
var keys = [];
//console.log("keys is of type " + typeof(keys));
//boolean
var x = true;
//console.log(x + " is of type " + typeof(x));
//DOM element - listed as an object
var title = document.getElementById("title");
console.log(title);
//console.log("title is of type " + typeof(title));
//Function type - can store entire functions in variables
var added = function(){ return 5+5; };
//console.log(typeof(added));
//console.log(added);
//console.log(added());
//zip = 10024;
//console.log(zip);