JavaScript: Some most basic things that developer needs to know

Hello everyone. My name is Asfakur Rahman. In this article i want to discuss about something basic bust most important things for all the JS developer. If you have some time, please read my article & follow me. Thank you

Here is a short list that i want to discuss in this article:

  1. Truthy and Falsy values
  2. double equal (==) vs triple equal (===), implicit conversion
  3. Scope, block scope, access outer scope
  4. Closure, encapsulation, private variable
  5. difference between call and apply
  6. Remove duplicate item from an array
  7. Count the number of words in a string
  8. Reverse a string
  9. Create a Fibonacci Series using a for loop
  10. Check whether a number is a Prime Number or not

Truthy & Falsy Values:

Truthy & Falsy are boolean type methods that need to know that the given value in the function or in the variable is true or false.

Here is a example of a Truthy & Falsy :

In this example, if age variable value is 0 or less than 0, than the output would be false. Here are some values that define that output will be truthy or falsy:

double equal (==) vs triple equal (===), implicit conversion:

double equal & triple equal are almost same but there is a some differences. double equal doesn’t check data type of a variable. That’s why when see that both variable are same then it will output that condition is true. Here is the example:

On the other hand, triple equal check data type of variable. if there is 2 value & one is a integer , one is string, then it output that the given condition is false. Example:

Scope, block scope, access outer scope:

Scope needs to declare inside the function. Rather than that it will won’t able to work perfectly. Example:

If scope is outside of the function, those scope called as global scope. Here is the example of global scope:

There is things that is called as “Hoisting”, that means a variable that can be declared after it has been used in function. In other words we can say that, a variable that can be used before it has been declared in function. Here is the example of block scope:

Closure, encapsulation, private variable:

If you used to call one function from another function or you may return, then it makes a closed environment. After returning if it access the outside function, when it used all the variable with closed environment. Here is the example:

Differences between call and apply:

call

Example:

apply:

Example:

Remove duplicate item from an array:

Example:

Count the number of words in a string:

Example:

Reverse a string:

Example:

Create a Fibonacci Series using a for loop:

Example:

Check whether a number is a Prime Number or not:

Example:

Thanks for reading.