10 basic things you should know about Javascript.

Sudipto Acharjee
2 min readMay 8, 2021
  1. Truthy and Falsy values:
    const name=”shakib”
    if(name){
    console.log(“condition is true”)
    }else{
    console.log(“condition is false”)
    }
    Output: Condition is true.
    Here, it’s true because the value of the name has a string. if we give their const name=” ”; then the output is condition is false. Because the value of the name is an empty string.
  2. null vs undefined: if a function we don’t return completely or pass a parameter, then it will show output “undefined”.The value null represents the intentional absence of any object value.
  3. double equal(==)vs triple equal(===): when we are using == equal, that means we check both of value is equal or not.
    const first =2;
    const second =2;
    if(first==second){
    console.log(“condition is true”)
    }else{
    console.log(“condition is false”)
    }
    Output: the condition is true.
    On the other hand, (===) equal check both of the variable type and value.
  4. Scope and block scope: Scope is when we declare a function, then the value is only valid in the function area. we cannot catch or run the value outside a function.
    Block scope is the area within if, switch conditions or for and while loops. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.
  5. Closure and encapsulation: A closure gives you access to an outer function’s scope from an inner function. A closure is the combination of a function bundled together with reference to its surrounding state. Encapsulation includes the idea that the data of an object should not be directly exposed.
  6. bind and apply: The bind method creates a new function that, when called, has this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
    With the apply method, we can write a method that can be used on different objects.
  7. Window and setInterval: A global variable, window, representing the window in which the script is running, is exposed to JavaScript code.
    setInterval used to set up interval in a function with a fixed time delay between each call.
  8. Javascript setTimeout: The setTimeout() method sets a timer that executes a function or specified piece of code once the timer expires.
  9. Event loop stack: The event loop continuously checks the call stack to see if there’s any function that needs to run. While doing so, it adds any function call it finds to the call stack and executes each one in order.
  10. With a Set, learner can just do:
    function removeDuplicates(array) {
    return […new Set(array)]
    }
    First, convert an array of duplicates to a Set. The new Set will implicitly remove duplicate elements.
    Then, convert the set back to an array.

--

--