Which are two possible code fragments that you can insert at line 02 to achieve the goal?

You write the following JavaScript code. (Line numbers are included for reference only.)

You need to write a function that will initialize and encapsulate the member variable fullname.
Which are two possible code fragments that you can insert at line 02 to achieve the goal? Each correct answer presents a complete solution.
NOTE: Each correct selection is worth one point.
A. function Student(someName) { fullname=someName;
}
B. function Student (someName) { var fullname=someName;
}
C. function Student (fullname) {
This.fullname=fullname;
}
D. function Student (someName) { this.fullname=someName;
}

microsoft-exams

One thought on “Which are two possible code fragments that you can insert at line 02 to achieve the goal?

  1. Question doesn’t make sense. Only correct answer is D.
    A and B give undefined because you declare fullname as a variable and not an object property with ‘this’.
    C gives an error because ‘This’ does not exist, but ‘this’ does.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.