Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8555917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:14:03+00:00 2026-06-11T15:14:03+00:00

<html><head><script> function Pet(){ // Base Class var owner = Mrs. Jones; var gender =

  • 0
<html><head><script>
function Pet(){                                        // Base Class
    var owner = "Mrs. Jones";
    var gender = undefined;
    this.setOwner = function(who) { owner=who; };        //1
    this.getOwner = function(){ return owner; }
    this.setGender = function(sex) { gender=sex; }
    this.getGender = function(){ return gender; }
}

function Cat(){}                                       //subclass constructor
Cat.prototype = new Pet();  
Cat.prototype.constructor=Cat;
Cat.prototype.speak=function speak(){
    return("Meow");                                      //2
    };                                                   //3

function Dog(){};                                        //4     
Dog.prototype= new Pet();
Dog.prototype.constructor=Dog;
Dog.prototype.speak = function speak(){
    return("Woof");
    };                                                   //5

</script></head>
<body><script>

var cat = new Cat;
var dog = new Dog;
cat.setOwner("John Doe");
cat.setGender("Female");
dog.setGender("Male");
document.write(
     "<br>The cat is a "+ cat.getGender()+ " owned by "
     + cat.getOwner() +" and it says " + cat.speak());
document.write(
    "<br>The dog is a "+ dog.getGender() + " "
    + " owned by " + dog.getOwner() + " and it says " + dog.speak());
</script></body>
  1. Why are there semicolons after the closing curly braces in the above code at lines marked //1, //2, //3, //4 and //5 ?
  2. When will Cat.prototype = new Pet(); and Dog.prototype = new Pet(); be executed.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:14:05+00:00Added an answer on June 11, 2026 at 3:14 pm

    Well… JavaScript won’t put semicolons anywhere in your code on its own, the person who wrote the script did that, right?
    What JavaScript does though, is auto inserting semicolons in spaces you missed (not in your code, not visibly at least. It reads your code and then it behaves as if you had those auto inserted semicolons there when you wrote it). This can sometimes produce unexpected results.

    I suggest using semicolons after each statement, as noted in this great article.

    If I understand your second question correctly, then it goes like this:
    Javascript instantiates new Object based on object Pet’s prototype. Then points Cat.prototype to this newly created object. Same thing happens in case of Dog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {
<html> <head> <title>Question</title> <script type="text/javascript" > function MouseOverHand(ID) { var Cursor='hand'; var ID=ID; if
Sample code: <!DOCTYPE html> <html> <head> <title>test</title> <script language=javascript type=text/javascript> function init() { var
This is my HTML Code <html> <head> <title> Test Page </title> <script type='text/javascript'> function
Heres my simple html source <html> <head> <title> Dec2Bin </title> <script type=text/javascript> function app()
<!DOCTYPE HTML> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.js></script> <script type=text/javascript> $(#myBtn).on(click,function(){ alert('myBtn Clicked'); }); </script>
When I add this script to a plain HTML file's HEAD section <script type=text/javascript
I have written this scirpt: $(document).ready(function () { $('#tb1 li').hover(function () { var head
I have this function which is imported directly in the HTML function include(filename){ var
In my HTML-head i have this script included: <script id=mode type=text/javascript src=article.js></script> With a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.