I had been playing around with JavaScript examples (in Google Chrome's Developer Console), and noticed this representation [native code]
.
To my understanding: it seems to be something that comes as part of JavaScript itself
but that doesn't kill my curiosity. I'm looking for a better explanation to understand this [native code]
. So, precisely, I have these doubts:
- What qualifies as
[native code]
? Is it supposed to be just the functions only (function declarations), or can be any block of JavaScript code? - Can we turn our custom written code into a
[native code]
? If yes, how?
PS: I know SO guidelines suggest we shouldn't be asking multiple questions in one post. However, above two are related and clarifies our understanding for a single topic [native code]
, hence asked both together here.
Here's the working example, that prints [native code]
:
var doWork = function (name="Aaditya") {
console.log(name);
};
doWork(); // prints -- Aaditya
console.log(doWork); // prints -- ƒ (name="Aaditya") { return name; }
console.log(doWork.toString); // prints -- ƒ toString() { [native code] }
Edit:
I see that there is another similar post on SO What does “[native code]” mean?, but apparently, I haven't got an answer there (so, not sure if this should really be marked as a duplicate of that post or not, please suggest/help).