xxxxxxxxxx
var x = [1,2,3,4];
console.log(typeof x) // object
console.log(typeof null) // object
xxxxxxxxxx
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
xxxxxxxxxx
// You can use the built-in method 'typeof' in order to check the variable datatype
//examples:
typeof "hello" // "string"
//or
var a = 1;
typeof(a);
//the output will be > 'number'
xxxxxxxxxx
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
xxxxxxxxxx
There are two scopes of variables:
- Global variables - Defined anywhere in code
- Local variables - Defined in only function
xxxxxxxxxx
var var1 = "Hello, World!";
console.log(var1); // Output: Hello, World!
var1 = 42; // You can change the value of a variable declared with 'var'
console.log(var1); // Output: 42