Javascript error {[native code]}

Hi, I'm trying to make some basic javascript and get "native code" instead of what I want:

<script type="text/javascript"> var today = new Date(); document.write(today + "<br />"); //document.write(today.length + "<br />"); - was getting "undefined" //document.write(today[0] + "<br />"); - was getting "undefined" document.write(today.getMonth + "<br />"); document.write(today.getMonth + "<br />"); document.write(today.getFullYear + "<br />"); </script> 

:

 Fri Jan 13 14:13:01 EST 2012 function getMonth() { [native code] } function getDay() { [native code] } function getFullYear() { [native code] } 

I want to get the current month, day, year and put it in an array variable, which I will call later. Because of this code. Can someone tell me what it is and hopefully more importantly I can complete this project? Thanks for your time and help, it is very much appreciated!

+5
source share
5 answers

getMonth and the rest of the functions, not properties, when you call only today.getMonth , you get a link to the actual function. But if you execute it with parentheses, you will get the actual result.

Your code should be:

 document.write(today.getMonth() + "<br />"); document.write(today.getMonth() + "<br />"); document.write(today.getFullYear() + "<br />"); 
+10
source

You are missing a parenthesis () .

 document.write(today.getMonth() + "<br />"); document.write(today.getMonth() + "<br />"); document.write(today.getFullYear() + "<br />"); 
+2
source
 document.write(today.getMonth() + "<br />"); // notice the () to invoke the function document.write(today.getMonth() + "<br />"); document.write(today.getFullYear() + "<br />"); 
+1
source

getMonth and getFullYear are functions, so you need to call them. Pay attention to parentheses:

 document.write(today.getMonth() + "<br />"); document.write(today.getMonth() + "<br />"); document.write(today.getFullYear() + "<br />"); 

Like you, it prints string representations of functions, not function values.

+1
source

I am facing the same error, regarding my array value I get the String () function {[native code]}

  self.arrayToString = function (arrayval) { if (arrayval == "" || arrayval == null || arrayval == undefined) { return ""; } var arrString = ""; for (var indexval in arrayval) { if (indexval == 0) { arrString = (arrayval[indexval]); console.log("aray if statement values"+ arrString); } else { // arrString = arrString.concat("" + (arrayval[indexval])); arrString = arrString.concat("" + (arrayval[indexval])); console.log("aray values"+ arrString); } } return arrString; } 

for example, if my, var arrayval = "this is my code";

My conclusion:

this is my String () function code {[native code]}

0
source

Source: https://habr.com/ru/post/1390904/


All Articles