This course has been updated! We now recommend you take the Deep JavaScript Foundations, v3 course.

Check out a free preview of the full Deep JavaScript Foundations course:
The "The Bad Parts of Value Coercion" Lesson is part of the full, Deep JavaScript Foundations course featured in this preview video. Here's what you'd learn in this lesson:

Kyle reviews his thoughts about fixing coercion.

Get Unlimited Access Now

Transcript from the "The Bad Parts of Value Coercion" Lesson

>> Kyle: I've talked a lot about the problems of coercion. And I just wanna take a slight little detour here for a moment to say I really, genuinely wish that we could improve JavaScript rather than just talk about the bad parts of JavaScript. So there's a lot of junk that gets talked about in the bad parts of JavaScript and we just assume JavaScript will always be this poorly designed collection of mistakes and bugs and whatever.

[00:00:29] And I really wish that JavaScript had a future where we could eventually start fixing some of these things. And as I said earlier, I think that there is a way to do that. So I decided to sit and talk about if we were gonna fix coercion, I wanted to explore that topic.

[00:00:44] What would we have to do to fix coercion and what would that mean? And this was a blog post, a guest blog post that I wrote about fixing coercion. If I could go back and address it, how might we do that? Might we have a new mode that you could opt into similar to strip mode or something like that.

[00:01:00] Is there some way that we could begin to address coercion so that it actually makes sense. And this is just a list of some of the things that I would go back and change. I would for sure change that first one. Don't make the number coercion of empty string be 0.

[00:01:16] I'd probably change the null one. I might change the false and the true, I'd definitely change the string of location of arrays,to be more correct. This is just an example of some of the things I would effect and I talk about them more and more in this but there is also resource if your more interested in some of these new answers that corner cases if you will.

[00:01:36] This is a little grid that I created just it problematically generated but does the permutation of all different values and then the different conversions that we do. And I've arbitrarily marked which ones I think make sense versus which ones I think are crazy and I would change. You can explore that tool if this is more interesting to you, if not, don't worry about it.