1 00:00:00,880 --> 00:00:06,370 Welcome back to Lesson eight, Truthy and falsey, values and equality operators. 2 00:00:06,550 --> 00:00:12,010 So we looked at equality for comparison, for resolving true and false last time. 3 00:00:12,310 --> 00:00:17,520 But now we're going to bring in not just true and false, but truthy and false values. 4 00:00:17,530 --> 00:00:22,090 So Truthy and false values will resolve to true or false. 5 00:00:22,840 --> 00:00:29,200 And there are some things that if you just if the value is one of these things, an empty string or 6 00:00:29,200 --> 00:00:35,270 the number zero or the values null or undefined or the value not a number. 7 00:00:35,290 --> 00:00:38,920 So it's a no type, but it's trying to understand it as a number. 8 00:00:38,920 --> 00:00:45,340 But the value is actually not not a number that it can represent these if you just check to see their 9 00:00:45,340 --> 00:00:45,970 value. 10 00:00:46,300 --> 00:00:50,860 As far as Boolean logic, it's going to compute their value as false. 11 00:00:51,080 --> 00:00:56,320 OK, obviously if you printed something out that had this has its value, it would just give you this 12 00:00:56,320 --> 00:00:57,300 as the return. 13 00:00:57,850 --> 00:01:04,990 But if you're going to do a comparison between two things, it's going to understand them in their truthy 14 00:01:04,990 --> 00:01:07,180 value as falsey. 15 00:01:08,320 --> 00:01:13,410 And then there are some things here, like five being equal to five. 16 00:01:13,420 --> 00:01:15,820 This one is a string and this one is a number. 17 00:01:16,510 --> 00:01:22,030 If you check both of them with this equals, it's going to say, hey, these are the same value, even 18 00:01:22,030 --> 00:01:23,470 though they're not the same data type. 19 00:01:23,660 --> 00:01:27,100 If I compare them as the same value, then yes, that's true. 20 00:01:28,060 --> 00:01:33,130 If you say, are they exactly the same, then no, it's going to be like this one is a string. 21 00:01:33,160 --> 00:01:34,060 That one's a number. 22 00:01:34,510 --> 00:01:36,820 You can't convince me those are the exact same thing. 23 00:01:37,020 --> 00:01:41,200 OK, OK, so let's play with this in JavaScript a little bit. 24 00:01:41,660 --> 00:01:49,410 Let's just take let's just take this number and set it to fifty nine, OK? 25 00:01:50,810 --> 00:01:54,350 And let's do a little if if, Noam. 26 00:01:57,020 --> 00:02:04,100 So we're checking if this value and when you do if whatever's in parentheses will be evaluated for it's 27 00:02:04,100 --> 00:02:08,810 true or false value and so is fifty nine true? 28 00:02:09,170 --> 00:02:11,780 Well, yeah, it's Truthy because it's not zero. 29 00:02:12,020 --> 00:02:19,970 Zero is falsey, which means it will be interpreted by a boolean logic checker as false, but any other 30 00:02:19,970 --> 00:02:21,980 number is going to be resolved as true. 31 00:02:22,550 --> 00:02:25,030 OK, so let's just log. 32 00:02:31,650 --> 00:02:33,780 Variable is defined. 33 00:02:36,550 --> 00:02:38,170 And then we can do an else. 34 00:02:44,420 --> 00:02:46,010 And then check the value here, 35 00:02:49,130 --> 00:03:00,560 if it's not true, then let's just set this message that we're going to get variable has not been defined. 36 00:03:05,710 --> 00:03:06,070 OK, 37 00:03:09,400 --> 00:03:11,020 let's be extra clear about the. 38 00:03:12,970 --> 00:03:18,130 All right, so taking this, let's go ahead and print that out. 39 00:03:19,780 --> 00:03:21,460 Variable is defined. 40 00:03:21,490 --> 00:03:21,910 Why? 41 00:03:21,910 --> 00:03:23,410 Because we gave it a value. 42 00:03:24,730 --> 00:03:27,610 Now, what if we gave it zero? 43 00:03:28,100 --> 00:03:29,760 We initialized it with zero. 44 00:03:30,340 --> 00:03:31,460 What's going to happen now? 45 00:03:33,010 --> 00:03:34,880 Variable has not been defined. 46 00:03:35,110 --> 00:03:36,220 So we got a typo here. 47 00:03:38,210 --> 00:03:42,560 Variable has not been defined interesting, so it's technically defined. 48 00:03:43,510 --> 00:03:48,810 So we could clarify this as a false policy value. 49 00:04:02,750 --> 00:04:08,150 Now, obviously, we can give things a true value directly, so we could just say, hey, it's true 50 00:04:09,320 --> 00:04:10,880 or we could just say it's false. 51 00:04:12,710 --> 00:04:16,520 But if we give it any one of these five things, zero. 52 00:04:19,350 --> 00:04:20,490 Or No. 53 00:04:24,960 --> 00:04:30,840 Or undefined, so we just don't define it or we give it an empty string. 54 00:04:38,400 --> 00:04:40,950 That has a true value because the string is not empty. 55 00:04:42,490 --> 00:04:49,090 There are two characters in here, so the spaces mean something, even one space means something, but 56 00:04:49,090 --> 00:04:53,710 make it a completely empty space with nothing between those quotes and it's false. 57 00:04:54,070 --> 00:04:54,880 Interesting, huh? 58 00:04:56,470 --> 00:05:00,150 Or we could do it as some some value. 59 00:05:00,160 --> 00:05:01,150 That's not a no. 60 00:05:03,070 --> 00:05:03,540 Hi. 61 00:05:06,790 --> 00:05:14,380 Check that that's false, but if we do some number, that's actually a number that's true. 62 00:05:15,190 --> 00:05:24,160 OK, so then we just tested for Truthy and false values and we tried a few different iterations to show 63 00:05:24,160 --> 00:05:24,880 you how those work. 64 00:05:25,450 --> 00:05:32,590 OK, and again, with the quality operators, just to recap those, if we wanted to give you the example 65 00:05:32,590 --> 00:05:37,080 here, let's just say this one is fifty nine, OK? 66 00:05:37,900 --> 00:05:47,770 And then we can use if and all statements to say, OK, this is exactly equal to fifty nine, then we 67 00:05:47,770 --> 00:05:53,140 can say OK, yes, variable has a value of fifty nine. 68 00:05:58,510 --> 00:06:06,490 And this one does not have a value of fifty nine. 69 00:06:08,930 --> 00:06:12,440 OK, it has a value of fifty nine. 70 00:06:12,470 --> 00:06:14,360 What if we change this to 71 00:06:17,480 --> 00:06:19,610 a string called fifty nine? 72 00:06:19,790 --> 00:06:20,660 That won't work. 73 00:06:21,730 --> 00:06:27,460 It does not have a value of fifty nine because it's the wrong data type strings are not numbers, but 74 00:06:27,460 --> 00:06:35,020 they can be interpreted as numbers if you use this comparison operator, says a similarity operator, 75 00:06:35,020 --> 00:06:35,560 and we check it. 76 00:06:37,390 --> 00:06:42,640 The value inside the quotes is the same as the value right here for the number, so it will interpret 77 00:06:42,640 --> 00:06:43,090 it that way. 78 00:06:43,810 --> 00:06:50,050 OK, so that's Truthy and falsey values and the comparison operator for equality. 79 00:06:51,220 --> 00:06:56,350 This is checks for the same value and data type, and this is just producing value only. 80 00:06:56,950 --> 00:06:58,860 All right, see you in the next video.