mirror of
				https://github.com/flynx/Course-JavaScript.git
				synced 2025-10-31 03:50:10 +00:00 
			
		
		
		
	expanded on the null/undefined/NaN checking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									0d457175fa
								
							
						
					
					
						commit
						0cdd291043
					
				| @ -209,8 +209,27 @@ | ||||
| 
 | ||||
| // a couple notable types that can be counter-intuitive:
 | ||||
| 
 | ||||
| 	typeof(null) // -> 'object'
 | ||||
| 	typeof(NaN) // -> 'number'
 | ||||
| 	typeof(null) // -> 'object'
 | ||||
| 
 | ||||
| // For NaN use:
 | ||||
| 
 | ||||
| 	isNaN(NaN) // -> true
 | ||||
| 
 | ||||
| // And for null/undefined a more generic and non-strict comparison is 
 | ||||
| // recommended:
 | ||||
| 
 | ||||
| 	var x = null | ||||
| 	var y = undefined | ||||
| 
 | ||||
| 	x == null // -> true
 | ||||
| 	y == null // -> true
 | ||||
| 
 | ||||
| // Strict comparisons also work but unless explicitly required they 
 | ||||
| // should be avoided in favor of the non-strict comparison shown above:
 | ||||
| 
 | ||||
| 	x === null // -> true
 | ||||
| 	y === undefined // -> true
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user