Here is my latest discovery while experimenting with JS:
(function() { return this; }).call('string literal');
// => [String: 'string literal'] in V8
// => String { "string literal" } in FF
I stumbled on this while doing the following:
(function() { return this === 'string literal'; }).call('string literal');
// => false
Can anyone tell me why this
inside the function is not exactly what was passed as the first argument to call
?
Edit 1
What is the difference between string primitives and String objects in JavaScript? has been marked as a possible duplicate of my question.
While the answers to both questions are related to how JS wraps primitives inside Objects, I believe the questions, and their answers, are not identical.
My question was "why are the argument passed to call and the value of this inside the function different?", while the other question was "why is code block 1 faster than code block 2?"
The correct answer to my question was "because you did not use strict mode" while the answer to the other question was related to how fast data is accessed internally by engines implementing ECMAScript.
I hope this clarification is correct