কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে অবজেক্টের ভ্যালু পরিবর্তন হয়েছে কিনা যাচাই করুন এবং অন্য ভ্যালু আপডেট করুন


এটি যাচাই করতে, গেটার (get property) কনসেপ্ট ব্যবহার করুন। নিচের কোডটি দেখুন −

উদাহরণ

class Student{    constructor(studentMarks1, studentMarks2){       this.studentMarks1 = studentMarks1       this.studentMarks2 = studentMarks2       var alteredValue = this;       this.getValues = {          get studentMarks1() {             return alteredValue.studentMarks1          },          get studentMarks2() {             return alteredValue.studentMarks2          }       }    } } var johnSmith = new Student(78,79) console.log("Before incrementing the result is=") console.log("StudentMarks1="+johnSmith.studentMarks1,"StudentMarks2="+johnSmith.studentMarks2); johnSmith.studentMarks2+=10; console.log("After incrementing the value 10 in the studentMarks2, the result is as follows=") console.log("StudentMarks1="+johnSmith.studentMarks1, "StudentMarks2="+johnSmith.getValues.studentMarks2);

উপরোক্ত প্রোগ্রাম চালাতে নিচের কমান্ডটি ব্যবহার করুন −

node fileName.js.

এখানে, আমার ফাইলটির নাম demo200.js।

আউটপুট

এটি নিচের আউটপুট তৈরি করবে −

PS C:\Users\Amit\javascript-code> node demo200.js Before incrementing the result is= StudentMarks1=78 StudentMarks2=79 After incrementing the value 10 in the studentMarks2, the result is as follows= StudentMarks1=78 StudentMarks2=89

  1. জাভাস্ক্রিপ্টে একটি স্ট্রিং-এ নির্দিষ্ট টেক্সট রয়েছে কিনা তা কীভাবে যাচাই করবেন?

  2. জাভাস্ক্রিপ্টে পাস বাই ভ্যালু ব্যাখ্যা

  3. CSS এবং JavaScript ব্যবহার করে ক্লাস নাম অনুযায়ী DIV এলিমেন্ট ফিল্টার করার পদ্ধতি

  4. জাভাস্ক্রিপ্টে কোনো অবজেক্ট ক্লাসের ইনস্ট্যান্স কিনা যাচাই করা