1

I have been following javascript tutorial from www.w3school.com and while reading one of the examples i have got one question in my mind, the code is as follows:

<html> <body> <script type="text/javascript"> var txt =new String ("Hello World!"); document.write(txt.constructor); </script> </body> </html> 

Now, iam getting in response of this code is :

function String() { [native code] } 

However, according to me the constructor must have a parameter in it somewhat like this:

function string(value){} 

Can anybody please tell me why it is returning the constructor with no parameter.

1

2 Answers 2

2

Even no parameter defined in a JavaScript function, we still can get the parameters with arguments:

function test() { console.log(arguments); } test(1,3,6); // Output "[1,3,6]" in console. 
Sign up to request clarification or add additional context in comments.

Comments

0

The other comments are true, but they don't address your question. The reason you're not seeing any parameters, and why it's saying "[native code]" instead of the actual content of the function, is that window.String is a native function - it is not a reference to a javascript function, but instead a symbol that instructs the browser what to do when it's running your javascript. Think of it as more analogous to a plus sign than a function.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.