1. Confusion while using equality operators
|‘ ‘ == false||True|
|‘ ‘ === false||False|
|’10’ == 10||True|
|’10’ === 10||False|
|‘ ‘== 0||True|
|‘ ‘=== 0||False|
2. Wrong / Incorrect Reference of this keyword
As you can see in above example if we try to access getMyName () method directly (in first image) using this keyword inside set Timeout function it’s give error of ‘undefiled is not a function’ it’s due to execution context scope. So, for solution we store ref of current context in some variable and after that we can use it for accessing the current context.
3. Confusing addition and concatenation
4. Ignoring ‘var’ and Scope’s usagIgnoring ‘var’ and Scope’s usagee
5. Callback hell (Assuming callbacks to be synchronous)
After 3 seconds the callback function is called but before it completes with its execution the rest code runs and that is a reason why the callback console.log was run last. Now the mistakes happens when we use something that will be return in callback function and used on other operation this leads to big logical glitch this is demonstrate in following example with its solution.
There are many errors which are similar to the ones that I mentioned. These errors don’t mean that there is some problem with your coding knowledge. These errors just shows that while you are concentrating on bigger errors, these small ones slip through your mind. These errors are the ones that are tedious to identify but can be solved easily. So better be aware of these small things that can be a huge problem in long run.
That’s it for today.
Have a good one.