JavaScript Object Part – 1

Full Stack Web Development Courses with Real-time projects Start Now!!

Program 1

<html>
    <head><title>Histry Object of JS</title>
         <script language="javascript">
            //  function display()
            //  {
                // using Literals
                // student ={stid:101,stname:"Vishal Sharma",stcourse:"BTech"}
                // document.writeln(student.stid)
                // document.writeln(student.stname)
                // document.writeln(student.stcourse)

                // using new key word
            //     student=new Object()
            //     student.stid=501
            //     student.stname="Rajesh Gupta"
            //     student.stemail="[email protected]"
            //     student.stcourse="MTech"
            //     document.writeln("Id "+student.stid)
            //     document.writeln("<br>Name: "+student.stname)
            //     document.writeln("<br>Email: "+student.stemail)
            //     document.writeln("<br>Course: "+student.stcourse)
            // }

         // Constructor
            function student(stid,stname,stcourse)
            {
                this.stid=stid
                this.stname=stname
                this.stcourse=stcourse
            }

               function display()
               {
                  st=new student(101,"Amitesh Verma","MCA")
                   document.writeln(st.stid)
                   document.writeln(st.stname)
                   document.writeln(st.stcourse)

               }

         </script>
    </head>
      <body>
        <center>
            <input type="button" value="Click here" onclick="display()"> 
        </center>
           </form>
      </body>
</html>

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses
Image

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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