1. Type conversion #8
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Yield, generator and async functionsto Type conversionType conversionto 1. Type conversionType conversion (or typecasting) means transfer of data from one data type to another. Implicit conversion happens when the compiler (for compiled languages) or runtime (for script languages like JavaScript) automatically converts data types. The source code can also explicitly require a conversion to take place.
Implicit Type Conversion (Coercion) is the automatic conversion (by JavaScript) of a value from one type to another to fit an operation you want to use.
== LOOSE equality operator
=== STRICT equality operator
It is generally recommended to avoid coercion(unless you want it) because it can cause inconsistencies and unknown bugs in your application. When you mistakenly use values of incompatible types for an operation, you should get an error and not "help" from JavaScript.
To avoid coercion it is recommended that you use the strict equality operator.
Explicit Type Conversion (Type Casting) is the intentional conversion of a value from one type to another. You can do this using data type constructors.
Double equality operator ( == ) is known as the loose equality operator. This operator applies loosed comparison when comparing values. If the values compared are different types, type coercion first occurs where the type of one value is converted to fit the other. Then, the values are compared. The types are not strictly checked only the values are strictly checked.
Triple equality operator ( === ) is known as the strict equality operator. This operator applies strict value and type comparison with values. Type coercion doesn't happen with this operator. If the types or values are different, the operator returns false. It only returns true if the types and values are equal.
If you are unsure of the type of a value, you can use the typeof operator.