Home of web learners

www.webn3rd.com

javascript have object oriented thing

In js,we can create class,object and method also.

Lets create a class:

<html>
<head>
    
</head>
<body>
    <script>
  class abc{
    shownumber() {
    return 8;
  }
    
    }
    let abco=new abc();
      document.write(abcoo.shownumber());

</script>       
</body>
</html>

output:

8

here,we create a class named abc,under this class we have a method shownumber which return 8

In abco variable,we create the object for abc class with the use of let keyword

So to call the method of abc class,in document.write we call the method via abco object variable and we ot returned 8 in output

We can create object and use it

There are many predefined object we use in javascript

Lets look an example:

<html>
<head>
    
</head>
<body>
    <script>
 
var i = Math.sqrt(81);
document.write(i);

</script>       
</body>
</html>

output:

9

Here,under math object there is a method,sqrt which we use to square root of number,here it is 9

webn3rd.com

About webn3rd