10 important topic for javascript beginner

Debakor Acharjee
4 min readMay 8, 2021

1 . Truthy and Falsy

In programming, sometimes we need to check values by true and false . When we checking the variable, truthy value declares that the value is true and falsy value declares that the value is false. sometimes we get confused about truthy and falsy value. Here I try to little bit solve this confusion

Always remember These six values are falsy

  • False
  • 0
  • “ ”
  • Null
  • Undefined
  • Nan

Without these six value, everything is truthy

Here is some example of truthy values that confuse us :

  • ‘0’ (when we write something inside string define true value)
  • ‘false’
  • [] (an empty array define true value )
  • {} (an empty object define true value)
  • function(){} (an “empty” function define true value)

2 . Null Vs Undefined

When we declare a variable but not assign a value it’s called undefined. Null means empty and non declare able value. Null and undefined both are falsy value

Now we can see the result is undefined because we could not call return statement of this function

Output of the following code null

3 . double equal (==) vs triple equal (===)

There are so many different between double equal ( == ) and triple equal ( === )When we write ( == ) It’s checks value equality only . It’s can not checks the values typeof.

The following code return “Condition is true”. But actually, the condition is not true. because num2 value is a string.

When we write ( === ) It’s checks value equality and type.

Now the same code return “Condition is false”

4 . Closure

Closure is a unique concept of javascript. When we put a function inside another function then it makes a closure environment. An inner function always can access variables and parameters outside the function. If we want to count something and counting value will be available for all functions then we must use a global variable. Closure keeps their state for multiple calls. closure return different value for different variable

Output of the following code 1, 2, 3 for first three consoles and 1, 2, for last two consoles. For result, the output is 1,2,3 .result2 is a different variable that why the result2 output is 1,2

5 . Call()

In javascript call() method used to call a function on different objects. Call allows a function to be included in one object to set and call for a different object. Call () gives a new value for the function. When we write a function on time then we accede to it another object without rewriting the new object

Now we can see the output of the following code Debakor Acharjee

6 . Apply ()

The apply() method allow to call a function and takes an argument as an array. The apply() method is close to the call() method. apply method allows an object to take the method of another object without rewriting the code. Using apply() method we can find the largest number of an array.

The output of the following code 5

7 . Global variable

When we declare a variable outside a function then it’s called a global variable.If we want to access our variable from anywhere then we should use a global variable. Because the global variable is a global scope and can access any function from anywhere. We should always use let or var for declaring a global variable

8 . Javascript

Javascript is a scripting programming language that allows controlling dynamic website content. Javascript is the most popular language in the world. Using javascript we can do a lot of things. Add a new Html file change the existing content and update anything. javascript can do everything related to the webpage calculate, manipulate and validate data. We can do larger calculation easily by using javascript

9 . Find Leap Year

With this function, we can easily find the year is leap-year or not leap-year . A year is a leap year if it is divisible by 100. if it is divisible by 100 then it is also divisible by 400 except this all other years evenly divisible by 4.If a year full fill this all condition then we say that this year is a leap year.

10 . Find The Largest Element of an Array

Now we can see the output Max number is 61.

Using for loop we can easily find the largest number of an array first we assumed that the first element of the array is the largest number. we declare a variable name max to store the value. Then we use for loop. for loop start checking the value from the length of 0 of the array. If the statement checks the current value of the array. If the value is larger than the max value then set the current value in a max variable. After checking every element of the array we get the largest value

--

--

Debakor Acharjee
0 Followers

Highly skilled and specialized Front End Developer looking for an opportunity to implement my knowledge of web development.