What is the Data type of the props passed from parent component to child?


Does the props that are passed from a parent to child, are in a string form? If i need to pass a prop that is a number , and later on, wanted use that number, say for example, a price/quantity, how can i do that? How can i convert the price prop to a number?


Have you tried casting?

let number = "1.23"

let float = Number(number);

If a prop is indeed a number, JavaScript will attempt coerce it to a Number in a math expression…

console.log(number * 3);    //  3.69

This is not a sure fire way, though. What about addition?

console.log(number + 4);    // 1.234

Casting is a bit more deterministic.

console.log(float + 4);    //  5.23


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.