DEV Community

FatimaAlam1234
FatimaAlam1234

Posted on • Updated on

JavaScript - Fundamentals

  • Ctrl+Shift+J - > To open inspect in Chrome.
  • Biggest release to the language ever -> ES/2015 (ES -> EcmaScript).

NULL-> it's type is null but javascript prints it's type as an object which is a bug but is not changed for legacy reasons.

A particular variable when declared is by default string.

Type Coercion

Basically how js treats '+' operator as a concatenation when it comes to string and not addition and how other mathematical operations preserve their natural nature.

To necessarily take user input as a certain data type -> use let fav = data_type(prompt());

console.log(`Hi ${1990-1000} years old`);
Enter fullscreen mode Exit fullscreen mode

Here JS expects an expression instead of a statement in ${}

/New

"new" keyword actually means it will create a new object everytime even if it calls a constructor function with global scope (i.e. not inside an object)

Image description

This Keyword

https://www.freecodecamp.org/news/javascript-this-keyword-binding-rules/

Null V/S Undefined

Undefined

  1. When a variable is declared but not initialized, or when a function does not return a value, the variable or the function’s result is undefined.
  2. Accessing an object property or array element that does not exist also results in undeclared.
  3. It is a primitive value.
let x; // variable declared but not initialized
console.log(x); // Output: undefined

function doSomething() {
  // no return statement, so the function returns undefined
}
console.log(doSomething()); // Output: undefined

let obj = {};
console.log(obj.property); // Output: undefined
Enter fullscreen mode Exit fullscreen mode

Output
undefined
undefined
undefined

Null

  1. It is a deliberate assignment that represents the absence of any object value.
  2. It is often used to explicitly indicate that a variable or object property should have no value or no reference to any object.
  3. It is also a primitive value.

Function Call in JS
So the entire flow goes like this:

For each loop of the event loop, one task is completed out of the callback queue.
Once that task is complete, the event loop visits the job queue. It completes all the micro tasks in the job queue before it looks into the next thing.
If both the queues got entries at the same point in time, the job queue gets preference over the callback queue.

Top comments (0)