0
<script type="text/javascript">
    function car(name,number)
    {
        this.name = name;
        this.number = number;
        this.model = function()
        {

            docoment.write("<h1>tata</h1>");
        }
    }
    var c1 = new car("hhb",215);
    var c2 = new car("jhg",98767);
    c1.model();
    document.write(c1.name);
</script>

I create a constructor CAR, but it means "c1.model();" doesn't return any value while calling the function.

1 Answers1

0

Calling document.write() just writes the value into the web page, it doesn't return anything. You need a return statement.

this.model = function() {
    return '<h1>tata</h1>';
};

Also, see Why is document.write considered a "bad practice"?

Barmar
  • 596,455
  • 48
  • 393
  • 495