InterviewSolution
Saved Bookmarks
| 1. |
What is NaN in JavaScript? |
|
Answer» The double NOT Bitwise operator is a “double tilde” (~~) operator in JavaScript. Let’s SAY we have the following variable: var val1 = 3.7; var val2;Now, use the double tilde operator and assign it to another variable: val2 = ~~val1;The example to work with double tilde operator: <!DOCTYPE html> <html> <body> <script> var val1 = 3.7; var val2; val2 = ~~val1; document.write(val2); </script> </body> </html>The output: 3 You can ACHIEVE the same RESULT from Math.floor() in JavaScript, but double tilde is considered faster: <!DOCTYPE html> <html> <body> <script> var val1 = 3.7; document.write(Math.floor(val1)); </script> </body> </html>The same output is VISIBLE: 3 |
|