10 Javascript features you might have missed

You already know much of Javascript. But today we are going to discuss 10 simple things or say tricks you will find helpful while writing your next program.

  1. Base conversion: Do you know Javascript can work as a number base conversion calculator for you? It can easily convert any string to decimal number from binary, octal or hexadecimal. What you need is just put the base, you want to convert from, as the second parameter. For example, parseInt(“11”,2) will return 3. [binary to decimal].

2. Simply string to number: You can obviously use parseInt or parseFloat to convert a string to a number. Let’s see a shorter technique. +“56" will return 56 (of type ‘Number’).

3. IIFE: When you write a function, you need to call it anywhere in the program to execute it. Can you execute it immediately. Yeah ! here is an example- (function(){return “Hello World.”})(). No need of calling. It’s called immediately.

4. Falsy values: You might have noticed these. But a quick list can help you remember them. Here are the values that return false.
false, 0, (""), NaN, null, and undefined.

5. For (key in object) loop: Probably sometime in your coding you needed to loop through the object keys and values. Looping manually is a bit tiring here.
You can use this loop to get the key as ‘key’ directly and the value as ‘object.key’.

6. for (value of array): Thought we have forEach, map and many other array functions, this loop can do many things very simply.

7. “==” or “===”: Just keep in mind that the first one doesn’t consider the type of the values (string, number etc). But the second one does.

8. What is the object value: You can find the object value with any specific key simply writing object.key. But here is another way that may help you object[“key”]. In many cases where you find the key not immediately the later syntax will come into effect.

9. Var, let or const: Let and const work in block, such as -if else or loop. Var works in the function scope. If you don’t define variable but just put the value it will take place in the global scope.

10. Recursion: Recursion is a type of function executed inside itself. But remember to give the terminating condition at the beginning of the function or it will overflow the stack.

Full Stack Web Developer | Javascript, React and Node Expert.