10 Tricky JavaScript Concepts

Rifa Tasfia
3 min readNov 5, 2020

Accessibility

Web accessibility means websites, technologies and tools are designed so that disable people can use them. Meaning that people can perceive, understand, interact and navigate with the web.

Fragment

In react often we render single elements or multiple elements. If we want to render multiple elements we will require div tag and inside the div tag we put the entire content. It will create an extra node. To solve this problem we can use Fragment tag.

Example:

We can also use only <> and </> tag instead of <Fragment> tag. This will cause same result.

Closure

Closure is the combination of a function bundled together. If we execute a function inside a function a closure is created. Closure saves the state of the outer function variable but does not expose those private variable. Simply we can say that a closure is a having access to the parent scope, even after the parent function has closed.

Window

It is represented by the browser window. It is automatically created by the browser. All global JavaScript variable, objects, functions etc automatically become window object. Global variables ate properties and global functions are methods of the window object.

Truthy Values

Truthy value means it will evaluate boolean true.

  1. “ ”
  2. “0”
  3. []
  4. {}
  5. true

These types are considered true.

Falsy Values

Falsy value means it will evaluate boolean false.

  1. 0
  2. “”
  3. undefined
  4. null
  5. NaN
  6. false

These types are considered false.

Hoisting

Hoisting is JavaScript’s default behavior. It moves all declaration to the top of current scope. We must remember that JavaScript only hoist declaration not initialization. Function declaration can also be hoisted. If we have function expression only the variable part will be hoisted.

Access Variable

In JavaScript let and const type variale can not be accessed from outside block scope. But var type variable can be accessed from outside.

The sequence of accessing variable can be (inner scope) -> parameter -> outer scope -> global variable (window)

Recursion

Recursion means a process where a function call itself. It is the process of repeating items in a self-similar way. An example of finding factorial using recursion is given below

Null vs Undefined

Null is an object. But undefined is a type itself. Null represents the intentional absence of any object value. Undefined basically means a variable has been declared but has not been assigned a value. Null indicates the absence of a value for a while. Undefined indicates the absence of variable itself

--

--

Rifa Tasfia
0 Followers

I am an undergraduate student of IIT, Jahangirnagar University. I am very much passionate about learning new technologies.