Things to know for a JavaScript developer in 2020

A JavaScript developer have to improve their coding skills as soon as ECMA comes up with new standard. They need to use the latest method/syntax to shorten the length of code or to use a new method of array which are optimized than existing methods. I am going to list 10 things here.
  1. Should know usage of let and const
    • Before declaring a variable, we need to see that its usage, like are we going to modified it or not? If we are not going to modified it then we should use const.

  2. How to remove duplicates from an array
    • To remove duplicates, we can use an algorithm using map. But ECMA has provided Set() to give you unique values among duplicates.
    • It is mostly on use case, if you are dealing with array of numbers, string then Set is right choice and if you want t remove duplicates from array of objects then using algorithm using map is correct choice.

  3. How to use spread operator on an array / object
    • We should use (...) spread operator to create a new object/array with values of existing object/array. 
    • e.g.
      const student = { name: "San", age: 25 };
      const student2 = { ...student, city: "Banglore" };

  4. How destructing helps development
    • A developer has to write less code due to destructing. We have seen that to access a property of an object, we had to type object.prop multiple times.
    • e.g.
      // props is an object
      //old way
      const name = props.name;
      const age = props.age;
      //latest way
      const { name, age } = props;

  5. Should use arrow functions
    • We have arrow functions which is reducing length of the code. You don't need to use function keyword or use this in the function, no need to write return (in case on one line method)
    • e.g.
      const getSum = (a,b) => a + b;

  6. Should know about Template Strings & Expression within string
    • Template Strings give you ability to have multi line strings and you can put any variable's value in a string.
    • e.g.
      let multiLineStr = `Should know about Template Strings & Expression within string. Template Strings give you ability to have multi line strings and you can use put any variable's value in a string.`;
      let expStr = `Line no:${lineNo} has this text=> ${multiLineStr}`;

  7. When to use conditional operator
    • We should use conditional operator only if there is less than 4 conditions to be checked or conditions are very simple to read and understand.
    • If conditions are growing in complexity then we should use if statements.

  8. Should write test cases
    • Developer should know to usage of unit testing library such as jest, mocha, chai etc.
    • We should write test cases to avoid production bugs. And writing test cases improves your coding style. You will be more concise to handle empty, null and undefined. 

  9. Should use localStorage and sessionStorage correctly
    • We should not blindly use localStorage for all kinds of work.
    • Need to identify the scenario if we need the client data if he browse to website again or not. If we need the data to run our logic then use localStorage else we should use sessionStorage.

  10. How to create standalone react component
    • There will be a lot of components which can be reuse in multiple files or multiple projects of an organization. To have this feasibility to the organization, a developer should know to create standalone react component and publish it a registry (can be on npm or your organization's registry)






Comments

Popular Posts