6 killer tricks to write less Javascript | extrovert.dev -->

6 killer tricks to write less Javascript

6 killer tricks to write less Javascript
Sunday, April 26, 2020
This post is for people who are lazy like me. I often find myself writing less code and also fewer comments (my bad). Writing fewer lines will not that impact your simple project but probably you can see some difference in a complex project. This will be very useful for people who just started coding javascript.
6 killer tricks to write less Javascript

let's start with an official tip

Ternary Operator:

let isEmpty=true;
if(isEmpty==true){
       console.log('Man this is empty');
} else {
      console.log('not Empty');
}
which can be written as 
isEmpty ? console.log('Man this is empty'): console.log('not empty');

For loop:

const lang=['c' , 'python' , 'javascript']
for (let i=0;i<lang.length;i++){
     const lang = lang[i];
    console.log(lang);
}
for(let lang of lang ) console.log(lang);

Assign value :

if (age){
 age=age;
}else {
age=18;
}
⇒ let age= age || 18;

Template Literals:

const blog='art'
const sentence = 'blogging is an' + blog + '!' ;

⇒ const sentence = blogging is an ${blog}!;

Destructuring :

const post ={
  data:{
         blog_title:'6 killer tricks to write less Javascript',
         author:'adarshreddy adelli',
};
}
const blog_title=post.data.blog_title;
const author=post.data.author;
⇒ const {blog_title , author } = post.data;

Identical keys and values :

const authorDetails ={
           name : name,
           email:email,
};

⇒ const authorDetails = { name , email};
Hope you liked this post. Thank you!

0 Response to 6 killer tricks to write less Javascript

Comments are personally moderated by our team. Promotions are not encouraged.

Post a Comment