JavaScript Questions: What is Coercion?

preview_player
Показать описание
Unlike many languages, JavaScript is very forgiving when it comes to data types. Coercion refers to the conversion of one type to another that JavaScript performs in certain operations. It can be a blessing at times, but also can cause problems. In this video we address the world of coercion.

For a complete list of all our tutorials:

Рекомендации по теме
Комментарии
Автор

I've said it before.. I'll say it again. This Chanel is pure gold.

kamichikora
Автор

In my opinion you are the best JavaScript instructor that i've found online, Sir Steven Hancock! Thank you very much!

fernandafernandes
Автор

Watched many of your Youtube videos and decided to take the plunge in Udemy for the full courses. Thanks for all you've shared with us on Youtube.

Golfina
Автор

Being very Honest, I found your JavaScript classes to be the most useful of the dozens of courses I have purchased on Udemy. Your teaching style and the clarity of your examples is better than any of the others I have seen to date. I have learnt and understood more from one viewing of your course than any textbook I have read. The DOM and the Functions always have confused me until I purchased your courses and now I do understand them. Have you considered doing courses on Node JS, Angular ? I would be the first to purchase them.

westfield
Автор

Thank you very much for this video and many others. I really like how you explain things, it's very easy to understand and you voice is very soothing.

martinyfelix
Автор

Thanks a lot for these videos. Your way of explaining things is excellent indeed, much more clear and direct than others. I'm learning a lot!

brunoabreu
Автор

Thanks for the video. This video helps me to learn Coercion.

viana
Автор

Still gold! clarity ...gonna watch all and like all

dq
Автор

i really love your video!!! you use simple example to demonstrate the feature of javascript case by case. your video is very easy to follow. I get the clear concept even though English is not my first language :)) cheers from Hong Kong!!

jamietse
Автор

Thanks for sharing this video... I was trying to execute one expression i.e "" && false // returns ""; can you please explain how this coerced and returns ""?

lincoinlincoin
Автор

Very educative video. But I'm curious about something. In the following code, I intentionally neglected to wrap *undefined* in quotes, and it logged "undefined" (sans quotes) to the console instead of 10. Why is that?

let i;

if(typeof i === undefined) {
i = 10;
};

console.log(i); // undefined

asmartbajan
Автор

If you're reading this in 2021:
1. The BigInt value 0n (zero n) is also a falsey value.
2. Instead of the 'if' condition, use short-circuit evaluation or nullish coalescing to assign values to variables.
let i;
i = i || 10 // Short-circuit evaluation (checks against any falsey value)
i ||= 10; // Short-circuit evaluation with a logical assignment operator (ES2021)
i = i ?? 10 // Nullish Coalescing (checks against undefined or null only)
i ??= 10; // Nullish Coalescing with logical assignment operator (ES2021)

generationwolves
Автор

Hi Shan!
Firstly I would like to thank you for your videos, I am certain that your channel is one of the best in explaining Things related to JavaScript, as the name is already quite obvious :P

This video has been posted a while ago, but I have a question...
Why does the JavaScript language has these features, that at first glance, at least from what I understand, were made to facilitate the use of the language, but in the end are just so troublesome and become another reason that might make us confused, and in the end we not only DON'T use these things, but also have to know how to avoid them? The people that created the language, as I am certain, are very smart people, wouldn't they know about this?

If JavaScript just didn't have this Type Coercion "feature", wouldn't it be just so much simpler?

You write your code and simply get an error:
-Ah, I probably forgot to convert that value before using it

instead of....

No error, you get some value, but you don't know why that is
-Why is this value showing here? I already used a conditional to make sure about it

It's like it is trying to solve a problem that does not need to be solved! It isn't worth the effort, on the contrary, I think even novice programmers wouldn't have too much difficulty in converting different types of values, so for me it seems this was made just to confuse things even more!

thiagomeneses