Javascript ninja secrets

ninja_secrets

It’s all about js cool tips and tricks which help day to day programming and reduce the time of developer. For more tricks you can also read Tips and Tricks.

Javascript ninja secrets part - 1

1. Use == instead of ===

== only check Equality and === check Equality as well as type.


[1] === 1    // is false
[1]  == 1    // is true
'1' == 1     // is true
'1' === 1    // is false
 [] == 0     // is true
 [] === 0     // is false
 '' == false   // is true but true == "a" is false
 '' === false // is false 

2. undefined, null, 0, false, NaN, ” (empty string) are all falsy.

3. Empty an array


var arr = [1, 2, 3];  
arr.length = 0; // arr will be equal to [].

4. while loop power


var no = 4;
while (no--) console.log(no); // 3 2 1 0

5. iterate object in forEach


var obj = { name: "xyz", age: 23 };

[obj].forEach((val)=>{
	console.log(val); //{ name: "xyz", age: 23 }
});

6. Power of join


var arr = ['one', 'two', 'three'];
var list = '<ul><li>' + arr.join('</li><li>') + '</li></ul>';

console.log(list);
//<ul><li>one</li><li>two</li><li>three</li></ul>

7. Create object clone


var obj = { 'name': 'xyz' };
var clone = Object.assign({}, obj);
clone.age = 23;
console.log(obj); // { 'name': 'xyz' };

8. Power of logical and/or


var bol = false;
bol || console.log(bol); // false

var bol = true;
bol && console.log(bol); // true

9. Power of Double negation


var no = 2;
console.log(no); // 2
console.log(!no); // false
console.log(!!no); // true boolean conversion of no value

// it’s just convert value into boolean form

10. toFixed is awesome


var no = 2.44567890;
no = no.toFixed(2);
console.log(no); // 2.45

You May Also Like

About the Author: admin

45 Comments

  1. Pingback: site Blog Name
  2. Pingback: WOW Blog
  3. Pingback: WOW Site Blog Name
  4. Pingback: xxlhq.top article
  5. Pingback: xxlhq.xyz article
  6. Pingback: xxlph.xyz article
  7. Pingback: xxxpics xyz
  8. Pingback: xxlph xyz
  9. Pingback: pornph xyz
  10. Pingback: xxxph top
  11. Pingback: xxlph.top article
  12. Pingback: xyz
  13. Pingback: adulthq top
  14. Pingback: xxxhd.top article
  15. Pingback: xnxxhd top
  16. Pingback: xxxhq top
  17. Pingback: pornph.xyz article
  18. Pingback: xxlhd xyz
  19. Pingback: adultpics top
  20. Pingback: xxxhq.top article
  21. Pingback: xxxph xyz
  22. Pingback: xnxxhd.top article
  23. Pingback: xxlhd.xyz article
  24. Pingback: pornph.top article
  25. Pingback: xxlhq xyz
  26. Pingback: xxlph top
  27. Pingback: xxxph.top article
  28. Pingback: adultph top
  29. Pingback: xxlhq top
  30. Pingback: adulthd top
  31. Pingback: adulthd xyz
  32. Pingback: pornph top
  33. Pingback: adulthq xyz
  34. Pingback: xxxph.xyz article
  35. Pingback: xxxhd top

Comments are closed.