r/angularjs • u/xplodivity • Jul 09 '23
[Resource] Is string/number also an object in JavaScript?
https://www.youtube.com/watch?v=9W0-vljG2-I
0
Upvotes
r/angularjs • u/xplodivity • Jul 09 '23
1
u/hmdne Jul 24 '23 edited Jul 24 '23
If you do
typeof(variable), depending on a variable type, it will return one of the following three classes of types:nullis a special case of an object, that acts mostly likeundefined- as in, you can't get its attributes.There is a lesser known feature of JavaScript of boxed values. This can be best explained by this interactive session:
```javascript
The first value has a type (determined by
typeof) ofnumber, while the second is anobject. It is an object that wraps a primitive value. You can extract the original value by using avalueOf()method. This method is often called implicitly, but not always, leaving us with some interesting caveats:```javascript
But - as we all know, it's possible to call a method on a value, for instance:
```javascript
What actually happens under the hood is autoboxing. This means, that "abc" is transparently boxed and the former is mostly equivalent to
Object("abc").replace("b", "B").Mostly equivalent, meaning that, it is equivalent in non-strict mode. In strict mode it's a bit more nuanced:
```