From the course: JavaScript: Best Practices for Data
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Type cast - JavaScript Tutorial
From the course: JavaScript: Best Practices for Data
Solution: Type cast
(upbeat music) - I'm going to start out with the typecasts that I need to do, based on those comments. So first off, line 11 says I need to typecast on line 12. And line 12 is working with data.tempC which is string, but I need to typecast that to a number. And so to do that, I want to use the number wrapper and just passing tempC to that wrapper. Then down line 16, I need to cast tempF to a string. And that tempF value here I just got, that is going to be a number and so I need to make sure that that number is a string for actually logging as part of the string. So I'm going to use the string wrapper and pass it tempF. Now you may notice, on line 13, we are grabbing the third value from the data object which has a value of false. And it's a string we want to work with that as a Boolean. So you may have found if you made changes to line 13, that the app stopped working. And that's because if you're tryin' to typecast the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Type cast strings with the String wrapper2m 58s
-
(Locked)
Type cast numbers with the Number wrapper1m 40s
-
(Locked)
Type cast Booleans using double negation2m 14s
-
(Locked)
Rely on implicit Boolean values in conditionals1m 45s
-
(Locked)
Challenge: Type cast1m 7s
-
(Locked)
Solution: Type cast2m 39s
-
(Locked)
-
-