Things,we should know about javascript

Z anika Nibir
4 min readMay 8, 2021

--

1.Null Vs Undefined

Null: It is an assigned value in JavaScript. That means it is an empty or non-existence value. If we throw an example here,

We can imagine a box, that send your friend with a gift as a variable .it just like that a variable can hold an object.the box can contain a gift. But after you receive that and open it you find there nothing. The box contains nothing or we can say it is a null value.

Example,

Null also is a primitive value that represent the intentional absence of value.

Undefined: It indicates that a variable that has not been assigned or declare. If in a function a value not returned, it throws an undefined error.

Example,

If we apparently set a variable to equal undefined. We will receive then undefined.

Also, if we set a non-existence property in an object, we will explore the output undefined

2.Truthy and Falsy values

Truthy: Truthy value is a value that consider true.

Everything is truthy includes these,

Example,

  1. True
  2. {} (empty object)
  3. [] (empty array)
  4. “0”
  5. “false”
  6. Function () {} (empty function)

Falsy: Falsy value is a value that consider false.

Example,

  1. False
  2. 0(zero)
  3. ‘’ or “” (empty string)
  4. Undefined
  5. NaN

These following values are always falsy

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

Double Equal: Double equal don not follow strict rules in testing JavaScript.it just compare between two value’s type.

Example,

5==”5";

//true

It just the values. Don’t notice that if these are number or string.

Triple Equal: It tests very strictly in JavaScript that means it compare both the type and the value

Example,

5===5;

//true

But,

5===”5";

//false

It returns false, because these are same value, different type.

4.Scope

It determines the visibility or accessibility of a variable or other resource for a code.

Block Scope: it means the area within if, switch condition for or while loop. We can say that in {} curly braces the space is a block.

Example,

It means let const not allow declare variable outside the block. These variable available only in the block.

5.Closure

It is a function that has the access to the parent scope, even after the parent function has closed.it has access its own scope, outer function’s variables and also the global variables.

Example,

When we return displayNamefunction in friend function then JavaScript engine don’t destroy the local variable it store the variable in other place, thats why the displayName function can use the variable end we find output.

6.Private variable

This type of variable is only available in its own class.it is not attainable for for global scope or any other subclasses

Example,

Outside the Student class function age is undefined cuz it is only available in Student class.

7. Encapsulation

It is a mechanism of restricting direct access to the object’s data. It builds the data with methods that operate the data. That means it requires the data security.

Example,

8.Bind, Call & Apply:

These 3 help t

Bind: The methods create a function with a specified this value.

Example,

Apply:The method calls a function with a given this value.it send arguments in an array.

Example,

Output: Furkan Andic acts with Aybuke Pusat in Her yerde sen;

Call: The method calls a function with a given this value.it send arguments one by one separated by comma.

Example,

Basically call & apply serve the same puspose.In one difference is just in call method it sends parameter one by one and apply send parameter in an array.

9.Global variable & Global scope

A variable that is declared outside the function and all script and function can access it.we call it global variable. And in this scope where the variable is declared this is global scope.

10. setTimeout, setInterval

SetTimeout:The method calls a function or evaluates an expression after a specified number of milliseconds.

SetInterval: The method calls a function or evaluates an expression at specified intervals.

--

--