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.
Type cast strings with the String wrapper - JavaScript Tutorial
From the course: JavaScript: Best Practices for Data
Type cast strings with the String wrapper
- [Instructor] I'm modeling working with data whose data type I can't be certain of. My array has a single element right now with the numeric value 55. If I want to work with that data as a string, there are a few approaches I can take. I have a forEach statement here that loops through my array, just that one element for now, and tries out three of those approaches. new String using the new keyword and the string wrapper, then the toString method, and then the string wrapper on its own. I'm using the console.table method here which can take complex data, like this set of nested objects, and display in the console in the table format which can make it easier to understand. I'm running my code using Live Server so in the browser console, there's that table, and it shows a label for each of the three approaches followed by the value and the resulting data type. With the new String statement, I get a data type of…
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)
-
-