Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # JS - Checking variable
- ## typeof:
- ```shell
- typeof NaN // 'number'
- ```
- ```shell
- typeof 0 // 'number'
- ```
- ```shell
- typeof undefined // 'undefined'
- ```
- ```shell
- typeof {} // 'object'
- ```
- ```shell
- typeof [] // 'object'
- ```
- ```shell
- typeof null // 'object'
- ```
- ```shell
- typeof new Date // 'object'
- ```
- ```shell
- typeof '' // 'string'
- ```
- ```shell
- typeof "" // 'string'
- ```
- ```shell
- typeof false // 'boolean'
- ```
- ```shell
- typeof Date // 'function'
- ```
- ```shell
- var a = { "x" : 0 };
- typeof a.x // 'number'
- ```
- ```shell
- var a ={ "x" : 0 };
- typeof a.z // 'undefined'
- ```
- ```shell
- var a = { "x" : 0 };
- typeof z.x // 'Uncaught ReferenceError: z is not defined'
- ```
- ## Comparison Operators:
- ```shell
- var a = NaN;
- if(a){console.log('->', a)} // false
- ```
- ```shell
- var a = NaN;
- if(a == NaN){console.log('->', a)} // false
- ```
- ```shell
- var a = '';
- if(a){console.log('->', a)} // false
- ```
- ```shell
- var a = ' ';
- if(a){console.log('->', a)} // true
- ```
- ```shell
- var a = 0;
- if(a){console.log('->', a)} // false
- ```
- ```shell
- var a = null;
- if(a){console.log('->', a)} // false
- ```
- ```shell
- var a = [];
- if(a){console.log('->', a)} // true
- ```
- ```shell
- var a = {};
- if(a){console.log('->', a)} // true
- ```
- ```shell
- var a = undefined;
- if(a){console.log('->', a)} // false
- var b;
- if(a){console.log('->', a)} // false
- var a = undefined;
- var b;
- if(a === b){console.log('->', a)} // true
- var a = undefined;
- // n is never defined
- if(a == n){console.log('->', a)} // 'Uncaught ReferenceError: n is not defined'
- ```
- ```shell
- // n is never defined
- if(n){console.log('->', n)} // 'Uncaught ReferenceError: n is not defined'
- ```
- ```shell
- // n is never defined
- var a = n
- if(a){console.log('->', a)} // 'Uncaught ReferenceError: n is not defined'
- ```
Add Comment
Please, Sign In to add comment