JavaScript: Topics To Know
Truthy & Falsy Value:
Truthy:
A value that is considered true
when encountered in a Boolean context is called truthy value. All values are truthy unless they are defined as falsy (i.e., except for false
, 0
, -0
, ""
, null
, undefined
, and NaN
).
Falsy: A value that is considered false
when encountered in a Boolean context is called falsy value. Any value which is explicitly false
, 0
, -0
, ""
, null
, undefined
, and NaN
Null Vs. Undefined:
You may think, null and undefined are same, but it’s not. Let’s explore the difference between them.
null: null has two important features:
- null is an empty or non-existent value.
- null must be assigned.
undefined: Undefined most typically means a variable has been declared, but not defined. Example:
let b;
console.log(b);
DOM: The elaboration of DOM is Document Object Model. DOM is bassically a platform or programming interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.
Every Element in a document is part of the document object model.
“this” keyword:
In JavavaScript this keyword is used to refer something indirectly to the object in context.
Example:
Here, this refers to object in context which is person.
Synchronous Operations:
Normally, JavaScript operations are synchronous and execute the code from top to bottom. And it means, every step in an operation waits for the previous step to execute completely.
Example:
Asynchronous Operations:
Usually, JavaScript shows blocking behavior, i.e. if you write a code where a while loop is executed for 3 seconds, in that case, in the meantime the browser will block everything. And after 3 seconds it will run the next command. This is where asynchronous operation comes. In case of this kind of operation, it does not block anything. We can think of a setTimeOut() function in this regard.
Example: