Shabnam Priyanka
3 min readNov 5, 2020

Basic Javascript

  • Truthy and Falsy values — any positive or negative number as a value is true and when you put 0 it will show false. Anything written in a string is true but an empty string is false. If you put empty string but put space inside it will be truthy. Even if you put 0 inside a string it will be truthy because the string is no longer empty. If you do not declare a variable then the answer will be false. Null is false. NAN is false not a number. If you manually put the value false it will be false. But if you put a false inside an empty string then it will become true.
  • Null Vs Undefined -
  1. If you declare a variable but forgot to set a value then it will show undefined.
  2. You declare a function without return then it will show undefined
  3. Also you write return after declaring function but didn’t mention what it will return then it will show undefined.
  4. Suppose you declare a function with 2 parameters but when you call a function if you don’t pass both of the parameters then also it will show undefined.
  5. Suppose you have declared a variable name undefined then it will show undefined value. Which is the wrong thing to do.
  • double equal (==) vs triple equal (===): javascript double equal and triple equal almost the same except the triple equal check strictly. The value and type need to be the same in triple equal 8 === 8 it is true. But if you put 8 === “8” then it will be false. However, 8 == “8” will be true in double equal because it checks for the value.
  • Apply map, filter, find on an array of object
  1. If you pass a function in a map then it can take up to 3 parameters (element, index, array). But most of the time you will work with elements only. Map is like a loop, it takes an element, loops around then shows in an array.
  2. Suppose you have a bunch of numbers in an array but you want some number then you will use a filter function. If the condition meets only then it will filter out or else it won’t.
  3. Find and filter is almost the same. But find looks for specific elements in an array.
  • Scope, global scope, block scope
  1. Suppose you declare a function then you cannot call the function outside of the function. In short, within the area you have to declare everything only then it can access or else javascript will give you big errors. You cannot call outside of the function that is call scope.
  2. Suppose you have a variable outside of a function then you can call inside the function. You can call the function from inside or outside. It is call global scope.
  3. Suppose you declared a condition inside {} with let or const then you cannot go outside of the scope. This is call block scope. To elaborate more, if you declare for loop using let or const then you cannot call function from outside of the bracket.
  • What is hoisting?

When you use let or const declaring if block or for loop then the block scope doesn’t allow it to declare outside. but when you declare a variable with var instead of let or const then it hoists up. Means if you declare var in if block or for loop then it is easily accessible. In short, hoisting is moving all declared variables to the top.