Things to remember about JavaScript

In JavaScript, each value has an inherent Boolean value usually known as truthy and falsy.

The following values are always falsy:

if (false)

if (null)

if (undefined)

if (0)

if (NaN)

if (“”)

The following values are always truthy:

if (true)

if ({})

if ([])

if (42)

if (“0”)

if (“false”)

Undefined vs null

Undefined has occurred when a variable is declared but no value is assigned to the variable or a function without a return type or without passing any value as a parameter or trying to access any property of an object.

var number;

console.log(number); //shows undefined

null in JavaScript is a non-existence value and must be assigned.

var number;

console.log(number); //shows undefined

== vs ===

== in JavaScript is used for comparing two variables, but it ignores the datatype of the variable and returns true only if the two operands

=== is used for comparing two variables, but this operator also checks datatype and compares two values and returns true only if both values and data types are the same for the two variables.

Hoisting

Hoisting in JavaScript is a behavior of moving the declaration of a variable up to the top of the scope or script or current function and accessible from anywhere of the script.

Global variable

A global variable is declared outside of any function or declared with a window object. It can be accessed from anywhere on the function. A global variable is usually declared with var. A global variable has global scope.

Local variable

A local variable is declared inside of any function. It can’t be accessed from anywhere on the function. It only can be accessed from that scope or function where it is declared. A local variable is usually declared with let or const. A local variable has local scope.

Block Scope

Generally in JavaScript code where {curly bracket} is visible there is a block. In this term let and const keywords are used to declare variables which means those variables exist only within the corresponding block.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store