1.

What is Number.NEGATIVE_INFINITY constant in JavaScript

Answer»

To reference an object's properties or methods, use the with keyword.

The syntax: 

with (obj){    properties USED without the object name and dot }

The “obj” becomes the default object for the duration of the block that FOLLOWS. Now the object’s properties and methods can be used without even naming the object.

The example demonstrates the usage of with keyword:

<html>    <head>    <title>JavaScipt with keyword</title>       <script>          function stock(count){             with(this){                inventory = count;             }          }          function product(pname, category, id){             this.pname = pname;             this.category  = category;             this.id  = id;             this.inventory = 0;             this.stock = stock;          }       </script>    </head>    <body>       <script>          VAR p = new product("SHIRT", "CLOTHING", 17);          p.stock(100);          document.write("Product Name : " + p.pname + "<br>");          document.write("Product Category : " + p.category + "<br>");          document.write("Product ID : " + p.id + "<br>");          document.write("Product Inventory : " + p.inventory + "<br>");       </script>    </body> </html>

The output:

Product Name : Shirt Product Category : Clothing Product ID : 17 Product Inventory : 100


Discussion

No Comment Found