Linked Questions
10 questions linked to/from javascript: do primitive strings have methods?
0
votes
2
answers
5k
views
How does String.prototype.something() actually work? [duplicate]
There was zero explanation about this in the book I'm reading. They just threw an example with this, and didn't bother to explain anything at all.
I keep testing and experimenting with this in an ...
7
votes
3
answers
747
views
Why does a primitive variable act like an Object? [duplicate]
If we add a method to Number function (or Boolean or String) like this
Number.prototype.sayMyNumber = function(){
return "My number is " + this;
}
and then create a number object assign it to a ...
2
votes
2
answers
132
views
Why do Javascript primitive values (e.g. name = "John") have properties and methods? [duplicate]
I am learning difference between primitive and reference datatypes in JS and am confused by primitive values because on one hand primitive values have no properties or methods but on the other hand I ...
2
votes
1
answer
128
views
properties and methods of strings and numbers JavaScript [duplicate]
The objects have properties and methods in Javascript.
The primitive data types don't have properties and methods.
But I don't understand from where properties and methods come from of strings and ...
2
votes
0
answers
59
views
why javascript number is called a primitive when it has __proto__ [duplicate]
var num = 1;
typeof num; //prints number
console.log(num.__proto__); //prints Number
console.log(num.__proto__.__proto__); //prints Object
When variable num is behaving like a typical Object then why ...
3
votes
0
answers
54
views
Does JavaScript create Objects of Variables I create ( Like be it String, Number etc. Except creating Object Variable itself) [duplicate]
I have this question in mind since I started learning JavaScript last month.
What I have tried?: I researched for it online almost on all good sites but didn't get satisfactory answer in laymans ...
1
vote
0
answers
44
views
Why are Strings JavaScript Primitives? [duplicate]
I'm not a JavaScript newbie, but I was reading MDN page on primitive data types and it caught my attention the following line:
A primitive (primitive value, primitive data type) is data that is not ...
8
votes
4
answers
1k
views
Why are methods of String.prototype available to string literals?
This question has come out of another, which concerns the behaviour of console.dir with string literals. In particular, see the comments on my answer.
As we all know, String objects in JavaScript ...
4
votes
1
answer
101
views
JavaScript: Why does false.something evaluate to undefined?
While learning about the optional chaining operator I experimented a bit and found out that these two evaluate to undefined:
false.nonExistingProperty // undefined
true.nonExistingProperty // ...
Sven's user avatar
- 13.4k
0
votes
1
answer
131
views
Are symbols acting like objects in JavaScript?
Are symbols acting like objects in JavaScript or a Symbol object is being created under the hood in the following example:
const symbol = Symbol();
Symbol.prototype.sayHello = function () {
console....