2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								title: Truthy Value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								---
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Description
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								A **truthy**  value is a value that translates to **true**  when evaluated in a _Boolean_  context.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								All values are **truthy**  unless they are defined as ** [falsy ](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/guide/english/javascript/falsy-values/index.md )** (i.e. except for `false` , `0` , `""` , `null` , `undefined`  and `NaN` ).
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Checking for Truthy Values on Variables
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								It is possible to check for a truthy value in a variable with a simple conditional:
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								if (variable) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  // When the variable has a truthy value the condition is true.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								You can also get the boolean value of a variable by using the bang operator (`!` ) twice:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								!!variable // When the variable is truthy, a double bang (!!) will evaluate to the Boolean true.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### Interesting JavaScript Rules concerning Truthy Values
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								#### These Are Interesting Truthy Values
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  '0' (a string containing a single zero) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  'false' (a string containing the text “false”) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  [] (an empty array) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  {} (an empty object) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  function(){} (an “empty” function) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								#### Comparing Interesting Truthy Values
  
						 
					
						
							
								
									
										
										
										
											2018-10-16 10:30:23 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  `false` , `zero`  and `''` (empty strings) are all equivalent. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  `null`  and `undefined`  are equivalent to themselves and each other but nothing else. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `NaN`  is not equivalent to anything –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `Infinity`  is truthy – `true`  or `false` ! 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  An empty array(`[]` ) is truthy – `true`  is `false`  and comparing with `false`  is `true` ?! 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-11 19:11:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## More Information
  
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:47:55 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								See also: < a > falsy< / a >  | < a  href = 'https://developer.mozilla.org/en-US/docs/Glossary/Truthy'  target = '_blank'  rel = 'nofollow' > MDN< / a >