Site icon DataFlair

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="rajesh@gmail.com"
            //     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>

 

Exit mobile version