Which is more suitable to use, isNaN or Number.isNaN() in JavaScript

In JavaScript, NaN is a valid value of the number type. console.log(typeof NaN); // number When prompted to verify if a value matches NaN or not, you’ll encounter an irony: NaN doesn’t equate to itself. Therefore, standard equality comparisons are ineffective for checking NaN values. if(NaN === NaN){ console.log(“NaN is equal to NaN”); } elseContinueContinue reading “Which is more suitable to use, isNaN or Number.isNaN() in JavaScript”

Do you know about TypeScript keyof operator?

In TypeScript, the keyof operator creates a union type of all the known public property names of the given type. To understand the actual use case of the keyof operator, let us consider the below example. There is a type created with an interface, interface IProduct { id: number; name: string; price: number; stock: number;ContinueContinue reading “Do you know about TypeScript keyof operator?”

Choosing Between for..in Loops and Object.values() in JavaScript

To determine whether to use a for…in loop or Object.values, consider a scenario with two objects const Product = { name:”product1″, price:100, } const ProductInvoice = { invoiceno : “invoice1”, customer : “customer1”, } These objects are linked to each other in the prototype chain. Object.setPrototypeOf(ProductInvoice, Product); Now, you iterate and list the values withContinueContinue reading “Choosing Between for..in Loops and Object.values() in JavaScript”

Object.values to iterate JavaScript object properties

In JavaScript, you can display the values of all public enumerable properties of an object by using Object.values(). For instance, if you have an object like the one depicted below: const Product = { name:”p1″, price:100, } You can output the values of all properties by utilizing Object.values() like this: let p = Object.values(Product); console.log(p);ContinueContinue reading “Object.values to iterate JavaScript object properties”

Video – Partial Type in TypeScript

This video explains Partial Type in TypeScript. interface IProduct { name: string; price: number; } function SaveProduct(product: Partial<IProduct>) { console.log(product.name); console.log(product.price); } SaveProduct({ name: “Laptop”, price: 1000 }); SaveProduct({ name: “Mobile”, price: 500 }); SaveProduct({ name: “Tablet”}); https://www.youtube.com/watch?v=q5wE_QjBtVU