This Questions opens up a lot of doors for beginners to understand more how Javascript works and helped me. The answers/comments given whilst helpful stop short at the bigger picture which I think could be helpful. I have written an answer in a way which assumes limited knowledge to the person that wants an answer. In 2016 that would have been the op.
Javascript was built to run in another environment rather than on a desktop or a server or any other programmable feature. In this case here, the Browser. It was built to interact with Browser API's such as The DOM and other useful Browser API's that have post dated it. Javascript itself does not come with built in modules e.g. to access the users host system/ create UI’s. It didn’t need this to implement what it was created for. Its nothing like Python or Java which come with built in modules which can access file systems along with various other capabilities through its built in Library/modules. Yes like any language we could install a library to access a file system however this will be blocked by the security of the Browsers Sandbox.
Javascript
Yes Javascript is a Programming Language but it is often referred to as a "scripting Language" although I'm yet to see thats an official term other than something that describes it well.
ECMAScript is a standard that all JS Engines within browsers adhere to. When we write our javascript code, we expect a result based on the ECMAScript specification. If using our own Functions e.g.
Const sayName(name) = ()=> {
return name
}
sayName('Kevin')
The JS engine (another program in itself written in another Language , more commonly C++) interprets our code within the execution. The JS engine has various functions that can be invoked and during the currently running execution. Firstly tho, the code is parsed and the parser recognises the keyword "Const" then expects the name of the Constant after and then followed by an = sign. The Parser does the same with the return keyword and also with the () and {}.
If any syntax is wrong anywhere within the program, the parser will fail and our execution will not go to the next phase of the engine which is the Abstract Syntax Tree ( Lets not worry about that today as we are in danger of going off topic.)
Once the Abstract Syntax Tree has been created I think this is where the Op ( and I ) used to get confused which is the phase where we reach the interpreter. Now the interpreter can clearly understand our simple function written above. However how about these "built in" things that Javascript comes with. E.g. Array String Math methods etc . Well as a developer of javascript we call these methods and in effect I like to see this as "our Job is done." We have called this Method. Now, whether it be a Static Method or an instance Method of one of our created objects e.g. an Array, I expect the exact result when my code is run that was promised to me by ECMAScript.
It’s important to note that some of these Functions/Methods may be implemented in Javascript, but most will be implemented in Lower Level code such as C/C++. This is similar to how Python works where it's built in modules are written in C and executed via the Python Interpretation. Back to Javascript - How these functions are implemented is not important to neither myself or ECMAScript. Its the choice of the Browser how it goes about doing this and some very talented lower level programmers. ( Those C programmers and those employed by the Browser to implement the functionality of the Engine to comply with ECMAScripts expected result). Now we have all the functionality we need, the interpreter gets to work and after other processes ( depending on what engine is used ) turns this into Machine Code that CPU's can understand ( again explaining this will be off topic). So If we are logging to the console a definition of a function/Method which is within the JS Engine that we didn't write ourself thats where we get the Native code. E.g.
console.log(Math.random)
Thats when we get
function random() {
[native code]
}
Above this is described by a good and experienced developer as "Native code will appear if its a function of the hosting environment" which is the Browser and gives SetTimeout as an example. Yes this will also appear as Native Code which is code we didn't write ourselves, but this is a Function of the Browser, not part of the Javascript Language itself. All functions/Methods not written by us e.g. within the browser or at a lower level will appear as “Native Code”.
Nodejs
Now however we have another runtime environment that the JS engine can fit into. A technology everyone knows as Nodejs. Our Browser are replaced with other Api’s more useful on a server. We can now access a filesystem within the Node runtime environment. There is nothing wrong with accessing a filesystem on our own server. These API’s are suited to servers, however we are still in a runtime environment, we still have a javascript interpreter, our code is still interpreted, we still call lower level functions during the interpretation, it just means we are inside the Nodejs runtime environment rather than our “favourite” Browser.