primitive wrapper constructor vs casting function
Be ware of the different of the primitive wrapper constructor and the casting function.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var value = "25";
var number = Number(value); //casting function
document.writeln(typeof number); //"number"
var obj = new Number(value); //constructor
document.writeln(typeof obj); //"object"
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Primitive Wrapper Class:
- Primitive wrapper class
- Object constructor acts as a factory method for primitive data types
- primitive wrapper constructor vs casting function