»Ë»Ñ Æ÷·³

[JavaScript] Truthy and Falsy Values5

 

20240709095826_uwBGlqFLHR.jpeg

 

 

20240709095829_hxUtui6l0s.jpeg

 

 

20240709095830_Emnxgae3m9.jpeg

 

 

20240709095832_zcLnxpLzho.jpeg

 

 

20240709095835_hxewnVY8tv.jpeg

 

 

20240709095838_XUs9oxHH8R.jpeg

 

 

20240709095841_edbgBVwyGR.jpeg

 

 

20240709095842_0Hq6uTssfj.jpeg

 

 

20240709095844_cYsc8AEPwA.jpeg

 

:

(1) Falsy values are values that are not exactly false, but becomes false when converted into a boolean. 


(2) ±×¸² 1: In Javascript, there are only five falsy values. 1️⃣ 0 2️⃣ ¡¯¡¯ 3️⃣ undefined 4️⃣ null 5️⃣ NaN

👉 All of these 5 values will converted to false when we attempt to convert them to a boolean. They¡¯re not exactly false initially, but they will become false when converted to a boolean. 


(3) Apart from those 5 falsy values mentioned in (2), everything else are truthy values. For example, any number that is not zero or any string that is not an empty string (¡®¡¯) will be converted to true when we attempt to convert them to a boolean.


(4) Although values can be converted to boolean type manually or explicitly, in practice, the conversion to boolean is always implicit, not explicit. 


(5) Javascript does type coercion to booleans (automatically) in 2 scenarios:

1️⃣ When using logical operators. (ÀÌÈÄ °­ÀÇ¿¡¼­ ´Ù·ïÁú °Í)

2️⃣ ±×¸² 2~4: In a logical context. For example: in the condition of an if else statement


(6) Triple equal (===) is a comparison operator. It is called strict equality operator. It is strict because it does not perform type coercion. And so, it only returns true when both values are exactly the same.


(7) Double equal (==) is also a comparison operator called loose equality operator. And unlike triple equal, it actually performs type coercion. 


(8) ±×¸² 5~7À» ÅëÇØ strict equality operator¿Í loose equality operatorÀÇ Â÷À̸¦ ÀÌÇØÇÒ °Í


(9) As a general rule for clean code, avoid the loose equality operator as much as you can. When comparing values, always use strict equality operator.


(10) ±×¸² 8~9: prompt() ÇÔ¼ö¿¡ ÀÎÀÚ¸¦ ÀÔ·ÂÇßÀ» ½Ã, ¹®ÀÚ¿­À» ¹ÝȯÇÑ´Ù.


(11) The opposite of strict equality operator (===) and loose equality operator (==) are: !==, !=

 

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°
÷ºÎÆÄÀÏ
  • IMG_8525.jpeg
  • IMG_8526.jpeg
  • IMG_8527.jpeg
  • IMG_8528.jpeg
  • IMG_8529.jpeg
  • IMG_8530.jpeg
  • IMG_8531.jpeg
  • IMG_8532.jpeg
  • IMG_8533.jpeg

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 °¨¼º°³¹ßÀÚ
2024-07-09 Á¡¾ÆÀÌÄÜ
  1. ´ñ±ÛÁÖ¼Òº¹»ç

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 anonymousStruct
2024-07-09 Á¡¾ÆÀÌÄÜ
  1. ´ñ±ÛÁÖ¼Òº¹»ç

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 °Ç¹æÁø½½¶óÀÓ
2024-07-10 * Á¡¾ÆÀÌÄÜ
  1. ´ñ±ÛÁÖ¼Òº¹»ç

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 °¨¼º°³¹ßÀÚ
2024-07-11 * Á¡¾ÆÀÌÄÜ
  1. ´ñ±ÛÁÖ¼Òº¹»ç

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 kaiger
2024-07-17 * Á¡¾ÆÀÌÄÜ
  1. ´ñ±ÛÁÖ¼Òº¹»ç
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û -¸ñ·Ïº¸±â