search

Home  >  Q&A  >  body text

Problem creating objects

<script>var a={}a.name='hahaha';a.age=20;a.say=function(){"hello"};document.write(a.say())< ;/script>/*Why does the browser output undefined when accessing the object say? Can't the function value be output directly? */

小龙小龙1671 days ago1017

reply all(2)I'll reply

  • Guanhui

    Guanhui2020-05-04 10:44:02

    Because there is no return in your say() method

    reply
    0
  • DY。

    correct answer. //say=function(){"hello"}; say=function(){return "hello"};

    DY。 · 2020-05-08 01:52:29
  • Cancelreply