The ==
(or !=
) operator performs an automatic type conversion if needed.
In the otherhand, the ===
(or !==
) operator will not perform any conversion. It compares both the value and type, which could be considered faster than ==
.
Code | Result |
[10] === 10 |
false |
[10] == 10 |
true |
'10' == 10 |
true |
'10' === 10 |
false |
[] == 0 |
true |
[] === 0 |
false |
'' == false |
true |
'' === false |
false |
true == "a" |
false |
In Javascript world undefined
, null
, 0
, false
, NaN
, ''
(empty string) are all considered as false values.
So while coding if you want to check if a variable have a falsy value or not you need check the variable against all of these. Your code would look messed up if you keep comparing against all of these.
Luckly, there is an easy way. You can apply negation operation on the variable twice (eg. !!variable
), which will convert the variable value to appropriate boolean equivalent.
Usage | Result |
trueFalseCheck(null) |
false |
trueFalseCheck('') |
false |
trueFalseCheck(0) |
false |
trueFalseCheck(undefined) |
false |
trueFalseCheck(false) |
false |
trueFalseCheck(NaN) |
false |
trueFalseCheck(true) |
true |
trueFalseCheck('Amiya') |
true |
trueFalseCheck(10) |
true |
Modern browsers add little up down arrows to number inputs called spinners.
You can turn them off visually like the below. This works in both Chrome and Firefox
The autocomplete attribute can be used to Enable/Disable the autocomplete feature of a HTML form element.
Note: The autocomplete attribute works with the following <input>
types: text
, search
, url
, tel
, email
, password
, datepickers
, range
, and color
.
This can be applied directly to the form to turn off the autocomplete features of all it child elements.
Also this attribute can be applied to individual elements.
You can create a cool horizontal devider element (hr
) using the below simple css code.
Here is a live example.
The ::selection
CSS pseudo-element applies rules to the portion of a document that has been highlighted (e.g., selected with the mouse or another pointing device) by the user.
Note that Only a small subset of CSS properties can be used in a rule using ::selection
in its selector : color
, background
, background-color
and text-shadow
.