{"id":124,"date":"2018-07-26T09:20:05","date_gmt":"2018-07-26T09:20:05","guid":{"rendered":"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=124"},"modified":"2018-08-02T06:14:29","modified_gmt":"2018-08-02T06:14:29","slug":"javascript-objects","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/chapter\/javascript-objects\/","title":{"rendered":"JavaScript Objects"},"content":{"raw":"<div>\r\n\r\n<strong>JavaScript Popup Boxes<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Alert Box<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">An alert box is often used if we want to ensure information to the user. When an alert box pops up, the user will have to click \"OK\" to proceed.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&lt;script&gt;\r\n\r\nalert(\"Hello World!\")\r\n\r\n&lt;\/script&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Confirm Box<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A\u00a0 confirm box is often used when you want the user to verify or accept something. When a confirm box pops up, the user will have to click either \"OK\" or \"Cancel\" to proceed. If the user clicks \"OK\", the box returns true. If the user clicks \"Cancel\", the box returns false.<\/p>\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0 Prompt Box<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either \"OK\" or \"Cancel\" to proceed after entering an input value. If the user clicks \"OK\u201c, the box returns the input value.If the user clicks \"Cancel\u201c, the box returns null.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\nalert(\"This is an Alert method\");\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-125 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58.png\" alt=\"\" width=\"548\" height=\"611\" \/><\/p>\r\n<strong>JavaScript - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;p&gt;Click the button to calculate x.&lt;\/p&gt;\r\n\r\n&lt;button onclick=\"myFunction()\"&gt;Try it&lt;\/button&gt; &lt;br\/&gt;\r\n\r\n&lt;br\/&gt;Enter first number:\r\n\r\n&lt;input type=\"text\" id=\"txt1\" name=\"text1\"&gt;Enter second number:\r\n\r\n&lt;input type=\"text\" id=\"txt2\" name=\"text2\"&gt;\r\n\r\n&lt;p id=\"demo\"&gt;&lt;\/p&gt;\r\n\r\n&lt;script&gt;\r\n\r\nfunction myFunction() {\r\n\r\nvar y = parseInt(document.getElementById(\"txt1\").value);\r\n\r\nvar z = parseInt(document.getElementById(\"txt2\").value);\r\n\r\nvar x = y + z;\r\n\r\ndocument.getElementById(\"demo\").innerHTML = x;\r\n\r\n}\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Output:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-126 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59.png\" alt=\"\" width=\"467\" height=\"375\" \/><\/p>\r\n\r\n<div>\r\n\r\n<strong>Using Arrays<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">An <strong>array<\/strong> is an ordered collection of values referenced by a single variable name. The syntax for creating an array variable is:<\/p>\r\n<p style=\"text-align: justify\"><strong>var <\/strong><em>variable<\/em><strong> = new Array(<\/strong><em>size<\/em><strong>);<\/strong><\/p>\r\n<p style=\"text-align: justify\">where <em>variable<\/em> is the name of the array variable and <em>size<\/em> is the number of elements in the array (optional).<\/p>\r\n<p style=\"text-align: justify\"><strong>var <\/strong><em>variable<\/em><strong> = new Array(<\/strong><em>values<\/em><strong>);<\/strong><\/p>\r\n<p style=\"text-align: justify\">where <em>values<\/em> are the array elements enclosed in quotes and separated by commas.<\/p>\r\n<p style=\"text-align: justify\"><strong>var <\/strong>Month<strong>=new Array(\u201c\u201d, \u201c<\/strong>January<strong>\u201d, \u201c<\/strong>February<strong>\u201d, \u201c<\/strong>March<strong>\u201d, \u201c<\/strong>April<strong>\u201d, \u201c<\/strong>May<strong>\u201d, \u201c<\/strong>June<strong> \u201d, \u201c<\/strong>July<strong>\u201d, \u201c<\/strong>August<strong>\u201d, \u201c<\/strong>September<strong>\u201d, \u201c<\/strong>October<strong>\u201d, \u201c<\/strong>November<strong>\u201d, \u201c<\/strong>December<strong>\u201d);<\/strong><\/p>\r\n<p style=\"text-align: justify\">To populate the array with values, use:<\/p>\r\n<p style=\"text-align: justify\"><em>variable<\/em><strong>[<\/strong>i<strong>]=<\/strong><em>value<\/em><strong>;<\/strong><\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>JavaScript - Functions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We can define a function using the <strong>function<\/strong> keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.<\/p>\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\n&lt;!--function functionname(parameter-list)\r\n\r\n{\r\n\r\nstatements\r\n\r\n}\/\/--&gt;\r\n\r\n&lt;\/script&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\n&lt;!--\r\n\r\nfunction sayHello()\r\n\r\n{\r\n\r\nalert(\"Hello there\");\r\n\r\n}\r\n\r\n\/\/--&gt;\r\n\r\n&lt;\/script&gt;\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0 Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\nfunction sayHello()\r\n\r\n{\r\n\r\ndocument.write (\"Hello there!\");\r\n\r\n}\r\n\r\n&lt;\/script&gt;\u00a0 &lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;p&gt;Click the followingbutton to call the function&lt;\/p&gt; &lt;form&gt;\r\n\r\n&lt;input type=\"button\" onClick=\"sayHello()\" value=\"Say Hello\"&gt;\r\n\r\n&lt;p&gt; Use different text in write method and then try\u2026 &lt;p&gt; &lt;\/form&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>OUTPUT:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-127 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60.png\" alt=\"\" width=\"373\" height=\"275\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Function Parameters<\/strong>\r\n\r\n&nbsp;\r\n\r\nIt can take multiple parameters separated by comma.\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\nfunction sayHello(name, age) {\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">document.write (name + \" is \" + age + \" years old.\"); }<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt; &lt;\/head&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click the following button to call the function&lt;\/p&gt; &lt;form&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;input type=\"button\" onClick=\"sayHello('Zara', 7)\" value=\"Say Hello\"&gt; &lt;\/form&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Use different parameters inside the function and then try...&lt;\/p&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span>\r\n\r\n<\/div>\r\n<strong>\u00a0 OUTPUT<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-128 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61.png\" alt=\"\" width=\"482\" height=\"263\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0The return Statement<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe Function can have an optional <strong>return<\/strong> statement. This statement should be the last statement in a function.\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\nfunction concatenate(first, last)\r\n\r\n{\r\n\r\nvar full;\r\n\r\nfull = first + last;\r\n\r\nreturn full; }\r\n\r\nfunction secondFunction()\r\n\r\n{\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">var result;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">result = concatenate('Zara', 'Ali');<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">d<\/span><span style=\"text-align: initial;font-size: 1em\">ocument.write (result );<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">} &lt;\/script&gt; &lt;\/head&gt; &lt;body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click the following button to call the function&lt;\/p&gt; &lt;form&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;input type=\"button\" onClick=\"secondFunction()\" value=\"Call Function\"&gt; &lt;\/form&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Use different parameters insi de the function and then try...&lt;\/p&gt; &lt;\/body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span>\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0OUTPUT:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-129 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62.png\" alt=\"\" width=\"426\" height=\"269\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 JavaScript \u2013 Objects<\/strong>\r\n\r\n&nbsp;\r\n\r\nJavaScript is an Object Oriented Programming (OOP) Scripting language. It has the following features,\r\n\r\n&nbsp;\r\n\r\n1.\u00a0 \u00a0<strong>Encapsulation<\/strong>\r\n\r\n2.\u00a0\u00a0<strong>Aggregation<\/strong>\r\n\r\n3.\u00a0\u00a0<strong>Inheritance<\/strong>\r\n\r\n4.\u00a0 <strong>Polymorphism<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Object Properties:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Properties are the values associated with a JavaScript object.objectName.objectProperty = propertyValue;<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0example<\/strong>\r\n<div>\r\n\r\n\u00a0 \u00a0 \u00a0var str = document.title;\r\n\r\n&nbsp;\r\n\r\n<strong>Object Methods:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Methods are <strong>actions<\/strong> that can be performed on objects. Methods are stored in properties as <strong>function definitions<\/strong>.A function is a standalone unit of statements and a method is attached to an object and can be referenced by the <strong>this<\/strong> keyword.<\/p>\r\n&nbsp;\r\n\r\ndocument.write(\"This is test\");\r\n\r\n&nbsp;\r\n\r\n<strong>User-Defined Objects<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Objects are variables too. But objects can contain many values.var car = {type:\"Fiat\", model:\"500\", color:\"white\"}; where values are written as <strong>name:value<\/strong> pairsMethods are stored in properties as function definitions.All user-defined objects and built-in objects are descendants of an object called <strong>Object<\/strong>.<\/p>\r\n&nbsp;\r\n\r\n<strong>The new Operator<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The <strong>new<\/strong> operator is used to create an instance of an object. To create an object, the <strong>new<\/strong> operator is followed by the constructor method. The constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript functions.<\/p>\r\n&nbsp;\r\n\r\nvar employee = new Object();\r\n\r\nvar books = new Array(\"C++\", \"Perl\", \"Java\");\r\n\r\nvar day = new Date(\"August 15, 1947\");\r\n\r\n&nbsp;\r\n\r\n<strong>The Object() Constructor<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">JavaScript has built-in constructors for native objects like,<span style=\"text-align: initial;font-size: 1em\">var x1 = new Object(); var x2 = new String(); var x3 = new Number(); var x4 = new Boolean() var x5 = new Array(); var x6 = new RegExp();<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0 \/\/\u00a0 A new Object object\r\n\r\n\/\/\u00a0 A new String object\r\n\r\n\/\/\u00a0 A new Number object\r\n\r\n\/\/\u00a0 A new Boolean object\r\n\r\n\/\/\u00a0 A new Array object\r\n\r\n\/\/\u00a0 A new RegExp object\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0var x7 = new Function(); \/\/ A new Function object var x8 = new Date(); \/\/ A new Date object.<span style=\"text-align: initial;font-size: 1em\">We can create an \"object type\" using an built-in constructor function.<\/span><\/p>\r\n\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0Example :<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;User-defined objects&lt;\/title&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n<p style=\"text-align: justify\"><strong>var book = new Object();<\/strong> \/\/ Create the object book.subject = \u201cJAVA\"; \/\/ Assign properties to the object book.author = \u201cHerbert Schildt\u201d;<\/p>\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\ndocument.write(\"Book name is : \" + book.subject + \"&lt;br&gt;\"); document.write(\"Book author is : \" + book.author + \"&lt;br&gt;\"); &lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>OUTPUT:<\/strong>\r\n\r\n&nbsp;\r\n\r\nBook name is : JAVA\r\n\r\nBook author is : Herbert Schildt\r\n\r\n&nbsp;\r\n\r\n<strong>Working with Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We can create Object using a function (book) called as an object constructor. Once an object constructor is created, we can create new objects of the same type.<\/p>\r\n<p style=\"text-align: justify\">The example shows how we can create an \"object type\" using an object constructor function.<\/p>\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;User-defined objects&lt;\/title&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\nfunction addPrice(amount)\r\n\r\n{\r\n\r\nthis.price = amount;\r\n\r\n}\r\n\r\n&nbsp;\r\n\r\n<strong>function book(title, author)<\/strong>\r\n\r\n<strong>{<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>this.title = title;<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>this.author\u00a0 = author;<\/strong>\r\n\r\n<strong>this.addPrice = addPrice;<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">}<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&lt;\/script&gt; &lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>var myBook = new book(\u201cJAVA\", \u201cHerbert Schildt\"); <\/strong>myBook.addPrice(100);\r\n\r\n&nbsp;\r\n\r\ndocument.write(\"Book title is : \" + myBook.title + \"&lt;br&gt;\");\r\n\r\ndocument.write(\"Book author is : \" + myBook.author + \"&lt;br&gt;\");\r\n\r\ndocument.write(\"Book price is : \" + myBook.price + \"&lt;br&gt;\");\r\n\r\n&nbsp;\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\n<strong>OUTPUT:<\/strong>\r\n\r\n&nbsp;\r\n\r\nBook title is : JAVA\r\n\r\nBook author is : Herbert Schildt\r\n\r\nBook price is : 100\r\n\r\n&nbsp;\r\n\r\n<strong>The 'with' Keyword<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The object specified as an argument '<strong>with'<\/strong> becomes the default object for the duration of the block that follows. The properties and methods for the object can be used without naming the object.<\/p>\r\n&nbsp;\r\n\r\n<strong>Syntax :<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>with (object)<\/strong>\r\n\r\n<strong>{<\/strong>\r\n\r\n<strong>properties used without the object name and dot<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;User-defined objects&lt;\/title&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\n\/\/\u00a0 Define a function which will work as a method function addPrice(amount){\r\n\r\n<strong>with(this) <\/strong>{ price = amount;\r\n\r\n}\r\n\r\n}\r\n\r\nfunction book(title, author){ this.title = title;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">this.author\u00a0 = author;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">this.price = 0;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">t<\/span><span style=\"text-align: initial;font-size: 1em\">his.addPrice = addPrice; \/\/ Assign that method as property.<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">}<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;script type=\"text\/javascript\"&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">var myBook = new book(\u201cJAVA\", \u201cHerbert Schildt\"); myBook.addPrice(100);<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">document.write(\"Book title is : \" + myBook.title + \"&lt;br&gt;\");<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">d<\/span><span style=\"text-align: initial;font-size: 1em\">ocument.write(\"Book author is : \" + myBook.author + \"&lt;br&gt;\");<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">document.write(\"Book price is : \" + myBook.price + \"&lt;br&gt;\"); &lt;\/script&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><span style=\"text-align: initial;font-size: 1em\">\/html&gt;<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 OUTPUT:<\/strong>\r\n\r\nBook title is : JAVA\r\n\r\nBook author is : Herbert Schildt\r\n\r\nBook price is : 100\r\n\r\n&nbsp;\r\n\r\n<strong>JavaScript Native Objects<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following is the list of Built-in or Native objects. They are,\r\n\r\n&nbsp;\r\n\r\n1.\u00a0 \u00a0JavaScript Number Object\r\n\r\n2.\u00a0 JavaScript Boolean Object\r\n\r\n3.\u00a0 JavaScript String Object\r\n\r\n4.\u00a0 JavaScript Array Object\r\n\r\n5.\u00a0 JavaScript Date Object\r\n\r\n6.\u00a0 JavaScript Math Object\r\n\r\n7.\u00a0 JavaScript RegExp Object\r\n\r\n&nbsp;\r\n\r\n<strong>1.\u00a0<\/strong><strong>JavaScript - The Number Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The <strong>Number<\/strong> object represents numerical date, either integers or floating-point numbers.<\/p>\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\n&nbsp;\r\n\r\nvar v1 = new Number(number);\r\n<p style=\"text-align: justify\"><em>Note:<\/em> In the place of number, if you provide any non-number argument, then the argument cannot be converted into a number, it returns <strong>NaN<\/strong> (Not-a-Number).<\/p>\r\n&nbsp;\r\n\r\n<strong>Number Properties:<\/strong>\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, prototype, constructor<\/span>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0Number Methods<\/strong>:\r\n\r\n&nbsp;\r\n\r\ntoExponential()\r\n\r\ntoFixed()\r\n\r\ntoLocaleString()\r\n\r\ntoPrecision()\r\n\r\ntoString()\r\n\r\nvalueOf()\r\n\r\n&nbsp;\r\n\r\n<strong>2.\u00a0<\/strong><strong>JavaScript - The Boolean Object<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe <strong>Boolean<\/strong> object represents two values, either \"true\" or \"false\".\r\n\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\n&nbsp;\r\n\r\nvar v1 = new Boolean(value);\r\n\r\n&nbsp;\r\n\r\n<strong>Boolean Properties<\/strong>\r\n\r\n&nbsp;\r\n\r\nConstructor, prototype\r\n\r\n&nbsp;\r\n\r\n<strong>Boolean Methods<\/strong>\r\n\r\n&nbsp;\r\n\r\ntoSource( )\r\n\r\ntoString( )\r\n\r\nvalueOf( )\r\n\r\n&nbsp;\r\n\r\n<strong>3.\u00a0<\/strong><strong>JavaScript - The String Object<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe <strong>String<\/strong> Object help us to work with strings.\r\n\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\n&nbsp;\r\n\r\nvar str = new String(string);\r\n\r\n&nbsp;\r\n\r\n<strong>String Properties<\/strong>\r\n\r\n&nbsp;\r\n\r\nconstructor , length, prototype\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>String Methods<\/strong>\r\n\r\n&nbsp;\r\n\r\ncharAt(), charCodeAt(), concat(), indexOf(), lastIndexOf(), localeCompare(), match(), replace()\r\n\r\n&nbsp;\r\n\r\n<strong>String Object - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html &gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;Character Processing Methods&lt;\/title&gt;\r\n\r\n&lt;script type = \"text\/javascript\"&gt;\r\n\r\nvar s = \"ZEBRA\";\r\n\r\nvar s2 = \"AbCdEfG\";\r\n\r\ndocument.writeln( \"&lt;p&gt;Character at i ndex 0 in '\" + s + \"' is \" + s.charAt( 0 ) ); document.writeln( \"&lt;br \/&gt;Character code at index 0 in '\"+ s + \"' is \" + s.charCodeAt( 0 ) + \"&lt;\/p&gt;\" );\r\n\r\ndocument.writeln( \"&lt;p&gt;'\" + String.fromCharCode( 87, 79, 82, 68 ) + \"' contains character codes 87, 79, 82 and 68&lt;\/p&gt;\" )\r\n\r\ndocument.writeln( \"&lt;p&gt;'\" + s2 + \"' in lowercase is '\" +s2.toLowerCase() + \"'\" ); document.writeln( \"&lt;br \/&gt;'\" + s2 + \"' in uppercase is '\"+ s2.toUpperCase() + \"'&lt;\/p&gt;\" );\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/head&gt;&lt;body&gt;&lt;\/body&gt;&lt;\/html&gt;\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-130 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63.png\" alt=\"\" width=\"651\" height=\"425\" \/>\r\n\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a0 \u00a04.\u00a0\u00a0<\/strong><strong>JavaScript - The Arrays Object<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe <strong>Array<\/strong> object lets you store multiple values in a single variable of same date type. The maximum length allowed for an array is 4,294,967,295.\r\n\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\nvar fruits = new Array( \"apple\", \"orange\", \"mango\" );\r\n\r\ncreate array by simply assigning values\r\n\r\nvar fruits = [ \"apple\", \"orange\", \"mango\" ];\r\n\r\n&nbsp;\r\n\r\n<strong>Accessing array elements<\/strong>\r\n\r\n&nbsp;\r\n\r\nfruits[0] is the first element\r\n\r\nfruits[1] is the second element\r\n\r\nfruits[2] is the third element\r\n\r\n&nbsp;\r\n\r\n<strong>Array Properties<\/strong>\r\n\r\n&nbsp;\r\n\r\nConstructor, index, input, length, prototype\r\n\r\n&nbsp;\r\n\r\n<strong>Array Methods<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">concat(), every(), filter(), forEach(), indexOf(), join(), lastIndexOf(), map(), pop(), push() , reduce(), reduceRight(), reverse(), shift(), slice(), some(), toSource(), sort(), s plice(), toString(), unshift()<\/p>\r\n&nbsp;\r\n\r\n<strong>Array Object - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html &gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;Initializing an Array with a Declaration&lt;\/title&gt; &lt;script type = \"text\/javascript\"&gt;\r\n\r\nfunction start()\r\n\r\n{\r\n\r\nvar colors = new Array( \"cyan\", \"magenta\", \"yellow\", \"black\" ); var integers1 = [ 2, 4, 6, 8 ];\r\n\r\nvar integers2 = [ 2, , , 8 ];\r\n\r\noutputArray( \"Array colors contains\", colors ); outputArray( \"Array integers1 contains\", integers1 ); outputArray( \"Array integers2 contains\", integers2 );\r\n\r\n}\r\n\r\nfunction outputArray( header, theArray )\r\n\r\n{\r\n\r\ndocument.writeln( \"&lt;h2&gt;\" + header + \"&lt;\/h2&gt;\" ); document.writeln( \"&lt;table border = \\\"1\\\"\" +\"width = \\\"100%\\\"&gt;\" ); document.writeln( \"&lt;thead&gt;&lt;th width = \\\"100\\\" \" +\"align = \\\"left\\\"&gt;Subscript&lt;\/th&gt;\" + \"&lt;th align = \\\"left\\\"&gt;Value&lt;\/th&gt;&lt;\/thead&gt;&lt;tbody&gt;\" );\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">for ( var i = 0; i &lt; theArray.length; i++ )<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">document.writeln( \"&lt;tr&gt;&lt;td&gt;\" + i + \"&lt;\/td&gt;&lt;td&gt;\" + theArray[ i ] + \"&lt;\/td&gt;&lt;\/tr&gt;\" ); document.writeln( \"&lt;\/tbody&gt;&lt;\/table&gt;\" );<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">}<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;&lt;body onload = \"start()\"&gt;&lt;a href=index.html&gt;back&lt;\/a&gt;&lt;\/body&gt; &lt;\/html&gt;<\/span>\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-131 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64.png\" alt=\"\" width=\"653\" height=\"420\" \/><\/p>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 \u00a05.\u00a0<\/strong><strong>JavaScript - The Date Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Date objects are created with the <strong>new Date( )<\/strong>. Methods allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.<\/p>\r\n&nbsp;\r\n\r\n<strong>Syntax:<\/strong>\r\n\r\n&nbsp;\r\n\r\nnew Date( )\r\n\r\nnew Date(milliseconds)\r\n\r\nnew Date(date string)\r\n\r\nnew Date(year,month,date [,hour, minute, second, millisecond ])\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0Date Properties:<\/strong>\r\n\r\n&nbsp;\r\n\r\nconstructor, prototype\r\n\r\n&nbsp;\r\n\r\n<strong>Date Methods:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Date(), getDate(), getDay(), getFullYear(), getHours(), getMilliseconds(), getMinutes(), getMonth(), getSeconds(), getTime(), getTimezoneOffset(), getUTCDate(), setMinutes(), setMonth(), setSeconds(), setTime()<\/p>\r\n&nbsp;\r\n\r\n<strong>6.\u00a0<\/strong><strong>JavaScript - The Math Object<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Unlike other global objects, <strong>Math<\/strong> is not a constructor. All the properties and methods of <strong>Math<\/strong> are static and can be called by using Math as an object without creating it. <strong>Syntax<\/strong><\/p>\r\n&nbsp;\r\n\r\nvar pi_val = Math.PI;\r\n\r\nvar sine_val = Math.sin(30);\r\n\r\n&nbsp;\r\n\r\n<strong>Math Properties:<\/strong>\r\n\r\n&nbsp;\r\n\r\nE \\, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2\r\n\r\n&nbsp;\r\n\r\n<strong>Math Methods:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">abs(), acos() , asin(), atan() , atan2() , ceil(), cos(), exp(), floor(), log(), max(), min(), pow(), sin(), random(), round(), sqrt(), tan().<\/p>\r\n&nbsp;\r\n\r\n<strong>Math Object - Example<\/strong>\r\n\r\n&nbsp;\r\n\r\n&lt;html &gt;\r\n\r\n&lt;head&gt;\r\n\r\n&lt;title&gt;Finding the Maximum of Three Values&lt;\/title&gt; &lt;script type = \"text\/javascript\"&gt;\r\n\r\nvar input1 =\r\n\r\nwindow.prom pt( \"Enter first number\", \"0\" );\r\n\r\nvar input2 =\r\n\r\nwindow.prom pt( \"Enter second number\", \"0\" );\r\n\r\nvar input3 =window.prom\r\n\r\npt( \"Enter third number\", \"0\" );\r\n\r\nvar value1 = parseFloat( input1 );\r\n\r\nvar value2 = parseFloat( input2 );\r\n\r\nvar value3 = parseFloat( input3 );\r\n\r\nvar maxValue = maximum( value1, value2, value3 );\r\n\r\ndocument.writeln( \"First number: \" + value1 +\"&lt;br \/&gt;Second num ber: \" + value2\r\n\r\n+\r\n\r\n\\\"&lt;br \/&gt;Third num ber: \" + value3 +\"&lt;br \/&gt;Maximum is: \" + maxValue ); function maximum( x, y, z ){\r\n\r\n<span style=\"font-size: 1em;text-align: initial\">\u00a0return Math.max( x, Math.max( y, z ) );<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">}<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click Refresh (or Reload) to run the script again&lt;\/p&gt; &lt;a href=index.html&gt;back&lt;\/a&gt; &lt;\/body&gt;<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span>\r\n\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">OUTPUT:<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-132 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65.png\" alt=\"\" width=\"674\" height=\"454\" \/><\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">This module explains about JavaScript Dialog boxes with examples. This module also gives an idea about arrays, functions and objects. Moreover, the module also discusses about Objects that are of two types called native\/built-in objects and user defined objects.<\/p>\r\n\r\n<\/div>\r\n<strong>Web Links<\/strong>\r\n<ul>\r\n \t<li><em>www.w3schools.com<\/em><\/li>\r\n \t<li><em>http:\/\/www.tutorialspoint.com\/javascript<\/em><\/li>\r\n<\/ul>","rendered":"<div>\n<p><strong>JavaScript Popup Boxes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Alert Box<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">An alert box is often used if we want to ensure information to the user. When an alert box pops up, the user will have to click &#8220;OK&#8221; to proceed.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&lt;script&gt;<\/p>\n<p>alert(&#8220;Hello World!&#8221;)<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Confirm Box<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A\u00a0 confirm box is often used when you want the user to verify or accept something. When a confirm box pops up, the user will have to click either &#8220;OK&#8221; or &#8220;Cancel&#8221; to proceed. If the user clicks &#8220;OK&#8221;, the box returns true. If the user clicks &#8220;Cancel&#8221;, the box returns false.<\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0 Prompt Box<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either &#8220;OK&#8221; or &#8220;Cancel&#8221; to proceed after entering an input value. If the user clicks &#8220;OK\u201c, the box returns the input value.If the user clicks &#8220;Cancel\u201c, the box returns null.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>alert(&#8220;This is an Alert method&#8221;);<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-125 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58.png\" alt=\"\" width=\"548\" height=\"611\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58.png 548w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58-269x300.png 269w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58-65x72.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58-225x251.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-58-350x390.png 350w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/p>\n<p><strong>JavaScript &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;p&gt;Click the button to calculate x.&lt;\/p&gt;<\/p>\n<p>&lt;button onclick=&#8221;myFunction()&#8221;&gt;Try it&lt;\/button&gt; &lt;br\/&gt;<\/p>\n<p>&lt;br\/&gt;Enter first number:<\/p>\n<p>&lt;input type=&#8221;text&#8221; id=&#8221;txt1&#8243; name=&#8221;text1&#8243;&gt;Enter second number:<\/p>\n<p>&lt;input type=&#8221;text&#8221; id=&#8221;txt2&#8243; name=&#8221;text2&#8243;&gt;<\/p>\n<p>&lt;p id=&#8221;demo&#8221;&gt;&lt;\/p&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>function myFunction() {<\/p>\n<p>var y = parseInt(document.getElementById(&#8220;txt1&#8221;).value);<\/p>\n<p>var z = parseInt(document.getElementById(&#8220;txt2&#8221;).value);<\/p>\n<p>var x = y + z;<\/p>\n<p>document.getElementById(&#8220;demo&#8221;).innerHTML = x;<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-126 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59.png\" alt=\"\" width=\"467\" height=\"375\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59.png 467w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59-300x241.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59-65x52.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59-225x181.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-59-350x281.png 350w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/p>\n<div>\n<p><strong>Using Arrays<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">An <strong>array<\/strong> is an ordered collection of values referenced by a single variable name. The syntax for creating an array variable is:<\/p>\n<p style=\"text-align: justify\"><strong>var <\/strong><em>variable<\/em><strong> = new Array(<\/strong><em>size<\/em><strong>);<\/strong><\/p>\n<p style=\"text-align: justify\">where <em>variable<\/em> is the name of the array variable and <em>size<\/em> is the number of elements in the array (optional).<\/p>\n<p style=\"text-align: justify\"><strong>var <\/strong><em>variable<\/em><strong> = new Array(<\/strong><em>values<\/em><strong>);<\/strong><\/p>\n<p style=\"text-align: justify\">where <em>values<\/em> are the array elements enclosed in quotes and separated by commas.<\/p>\n<p style=\"text-align: justify\"><strong>var <\/strong>Month<strong>=new Array(\u201c\u201d, \u201c<\/strong>January<strong>\u201d, \u201c<\/strong>February<strong>\u201d, \u201c<\/strong>March<strong>\u201d, \u201c<\/strong>April<strong>\u201d, \u201c<\/strong>May<strong>\u201d, \u201c<\/strong>June<strong> \u201d, \u201c<\/strong>July<strong>\u201d, \u201c<\/strong>August<strong>\u201d, \u201c<\/strong>September<strong>\u201d, \u201c<\/strong>October<strong>\u201d, \u201c<\/strong>November<strong>\u201d, \u201c<\/strong>December<strong>\u201d);<\/strong><\/p>\n<p style=\"text-align: justify\">To populate the array with values, use:<\/p>\n<p style=\"text-align: justify\"><em>variable<\/em><strong>[<\/strong>i<strong>]=<\/strong><em>value<\/em><strong>;<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>JavaScript &#8211; Functions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We can define a function using the <strong>function<\/strong> keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>&lt;!&#8211;function functionname(parameter-list)<\/p>\n<p>{<\/p>\n<p>statements<\/p>\n<p>}\/\/&#8211;&gt;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>&lt;!&#8211;<\/p>\n<p>function sayHello()<\/p>\n<p>{<\/p>\n<p>alert(&#8220;Hello there&#8221;);<\/p>\n<p>}<\/p>\n<p>\/\/&#8211;&gt;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0 Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>function sayHello()<\/p>\n<p>{<\/p>\n<p>document.write (&#8220;Hello there!&#8221;);<\/p>\n<p>}<\/p>\n<p>&lt;\/script&gt;\u00a0 &lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;p&gt;Click the followingbutton to call the function&lt;\/p&gt; &lt;form&gt;<\/p>\n<p>&lt;input type=&#8221;button&#8221; onClick=&#8221;sayHello()&#8221; value=&#8221;Say Hello&#8221;&gt;<\/p>\n<p>&lt;p&gt; Use different text in write method and then try\u2026 &lt;p&gt; &lt;\/form&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>OUTPUT:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-127 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60.png\" alt=\"\" width=\"373\" height=\"275\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60.png 373w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60-300x221.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60-65x48.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60-225x166.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-60-350x258.png 350w\" sizes=\"auto, (max-width: 373px) 100vw, 373px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Function Parameters<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>It can take multiple parameters separated by comma.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>function sayHello(name, age) {<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">document.write (name + &#8221; is &#8221; + age + &#8221; years old.&#8221;); }<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt; &lt;\/head&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click the following button to call the function&lt;\/p&gt; &lt;form&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;input type=&#8221;button&#8221; onClick=&#8221;sayHello(&#8216;Zara&#8217;, 7)&#8221; value=&#8221;Say Hello&#8221;&gt; &lt;\/form&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Use different parameters inside the function and then try&#8230;&lt;\/p&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span><\/p>\n<\/div>\n<p><strong>\u00a0 OUTPUT<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-128 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61.png\" alt=\"\" width=\"482\" height=\"263\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61.png 482w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61-300x164.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61-65x35.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61-225x123.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-61-350x191.png 350w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0The return Statement<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The Function can have an optional <strong>return<\/strong> statement. This statement should be the last statement in a function.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>function concatenate(first, last)<\/p>\n<p>{<\/p>\n<p>var full;<\/p>\n<p>full = first + last;<\/p>\n<p>return full; }<\/p>\n<p>function secondFunction()<\/p>\n<p>{<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">var result;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">result = concatenate(&#8216;Zara&#8217;, &#8216;Ali&#8217;);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">d<\/span><span style=\"text-align: initial;font-size: 1em\">ocument.write (result );<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">} &lt;\/script&gt; &lt;\/head&gt; &lt;body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click the following button to call the function&lt;\/p&gt; &lt;form&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;input type=&#8221;button&#8221; onClick=&#8221;secondFunction()&#8221; value=&#8221;Call Function&#8221;&gt; &lt;\/form&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Use different parameters insi de the function and then try&#8230;&lt;\/p&gt; &lt;\/body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span><\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0OUTPUT:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-129 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62.png\" alt=\"\" width=\"426\" height=\"269\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62.png 426w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62-300x189.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62-225x142.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-62-350x221.png 350w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 JavaScript \u2013 Objects<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>JavaScript is an Object Oriented Programming (OOP) Scripting language. It has the following features,<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0 \u00a0<strong>Encapsulation<\/strong><\/p>\n<p>2.\u00a0\u00a0<strong>Aggregation<\/strong><\/p>\n<p>3.\u00a0\u00a0<strong>Inheritance<\/strong><\/p>\n<p>4.\u00a0 <strong>Polymorphism<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Object Properties:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Properties are the values associated with a JavaScript object.objectName.objectProperty = propertyValue;<\/p>\n<\/div>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0example<\/strong><\/p>\n<div>\n<p>\u00a0 \u00a0 \u00a0var str = document.title;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Object Methods:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Methods are <strong>actions<\/strong> that can be performed on objects. Methods are stored in properties as <strong>function definitions<\/strong>.A function is a standalone unit of statements and a method is attached to an object and can be referenced by the <strong>this<\/strong> keyword.<\/p>\n<p>&nbsp;<\/p>\n<p>document.write(&#8220;This is test&#8221;);<\/p>\n<p>&nbsp;<\/p>\n<p><strong>User-Defined Objects<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Objects are variables too. But objects can contain many values.var car = {type:&#8221;Fiat&#8221;, model:&#8221;500&#8243;, color:&#8221;white&#8221;}; where values are written as <strong>name:value<\/strong> pairsMethods are stored in properties as function definitions.All user-defined objects and built-in objects are descendants of an object called <strong>Object<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The new Operator<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The <strong>new<\/strong> operator is used to create an instance of an object. To create an object, the <strong>new<\/strong> operator is followed by the constructor method. The constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript functions.<\/p>\n<p>&nbsp;<\/p>\n<p>var employee = new Object();<\/p>\n<p>var books = new Array(&#8220;C++&#8221;, &#8220;Perl&#8221;, &#8220;Java&#8221;);<\/p>\n<p>var day = new Date(&#8220;August 15, 1947&#8221;);<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The Object() Constructor<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">JavaScript has built-in constructors for native objects like,<span style=\"text-align: initial;font-size: 1em\">var x1 = new Object(); var x2 = new String(); var x3 = new Number(); var x4 = new Boolean() var x5 = new Array(); var x6 = new RegExp();<\/span><\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0 \/\/\u00a0 A new Object object<\/p>\n<p>\/\/\u00a0 A new String object<\/p>\n<p>\/\/\u00a0 A new Number object<\/p>\n<p>\/\/\u00a0 A new Boolean object<\/p>\n<p>\/\/\u00a0 A new Array object<\/p>\n<p>\/\/\u00a0 A new RegExp object<\/p>\n<\/div>\n<p style=\"text-align: justify\">\u00a0 \u00a0var x7 = new Function(); \/\/ A new Function object var x8 = new Date(); \/\/ A new Date object.<span style=\"text-align: initial;font-size: 1em\">We can create an &#8220;object type&#8221; using an built-in constructor function.<\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0Example :<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;User-defined objects&lt;\/title&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p style=\"text-align: justify\"><strong>var book = new Object();<\/strong> \/\/ Create the object book.subject = \u201cJAVA&#8221;; \/\/ Assign properties to the object book.author = \u201cHerbert Schildt\u201d;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>document.write(&#8220;Book name is : &#8221; + book.subject + &#8220;&lt;br&gt;&#8221;); document.write(&#8220;Book author is : &#8221; + book.author + &#8220;&lt;br&gt;&#8221;); &lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>OUTPUT:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Book name is : JAVA<\/p>\n<p>Book author is : Herbert Schildt<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Working with Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We can create Object using a function (book) called as an object constructor. Once an object constructor is created, we can create new objects of the same type.<\/p>\n<p style=\"text-align: justify\">The example shows how we can create an &#8220;object type&#8221; using an object constructor function.<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;User-defined objects&lt;\/title&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>function addPrice(amount)<\/p>\n<p>{<\/p>\n<p>this.price = amount;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>function book(title, author)<\/strong><\/p>\n<p><strong>{<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>this.title = title;<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>this.author\u00a0 = author;<\/strong><\/p>\n<p><strong>this.addPrice = addPrice;<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">}<\/strong><\/p>\n<\/div>\n<div>\n<p>&lt;\/script&gt; &lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>var myBook = new book(\u201cJAVA&#8221;, \u201cHerbert Schildt&#8221;); <\/strong>myBook.addPrice(100);<\/p>\n<p>&nbsp;<\/p>\n<p>document.write(&#8220;Book title is : &#8221; + myBook.title + &#8220;&lt;br&gt;&#8221;);<\/p>\n<p>document.write(&#8220;Book author is : &#8221; + myBook.author + &#8220;&lt;br&gt;&#8221;);<\/p>\n<p>document.write(&#8220;Book price is : &#8221; + myBook.price + &#8220;&lt;br&gt;&#8221;);<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>OUTPUT:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Book title is : JAVA<\/p>\n<p>Book author is : Herbert Schildt<\/p>\n<p>Book price is : 100<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The &#8216;with&#8217; Keyword<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The object specified as an argument &#8216;<strong>with&#8217;<\/strong> becomes the default object for the duration of the block that follows. The properties and methods for the object can be used without naming the object.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax :<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>with (object)<\/strong><\/p>\n<p><strong>{<\/strong><\/p>\n<p><strong>properties used without the object name and dot<\/strong><\/p>\n<p><strong>}<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;User-defined objects&lt;\/title&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>\/\/\u00a0 Define a function which will work as a method function addPrice(amount){<\/p>\n<p><strong>with(this) <\/strong>{ price = amount;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>function book(title, author){ this.title = title;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">this.author\u00a0 = author;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">this.price = 0;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">t<\/span><span style=\"text-align: initial;font-size: 1em\">his.addPrice = addPrice; \/\/ Assign that method as property.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">}<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">var myBook = new book(\u201cJAVA&#8221;, \u201cHerbert Schildt&#8221;); myBook.addPrice(100);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">document.write(&#8220;Book title is : &#8221; + myBook.title + &#8220;&lt;br&gt;&#8221;);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">d<\/span><span style=\"text-align: initial;font-size: 1em\">ocument.write(&#8220;Book author is : &#8221; + myBook.author + &#8220;&lt;br&gt;&#8221;);<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">document.write(&#8220;Book price is : &#8221; + myBook.price + &#8220;&lt;br&gt;&#8221;); &lt;\/script&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;<\/span><span style=\"text-align: initial;font-size: 1em\">\/html&gt;<\/span><\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 OUTPUT:<\/strong><\/p>\n<p>Book title is : JAVA<\/p>\n<p>Book author is : Herbert Schildt<\/p>\n<p>Book price is : 100<\/p>\n<p>&nbsp;<\/p>\n<p><strong>JavaScript Native Objects<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following is the list of Built-in or Native objects. They are,<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0 \u00a0JavaScript Number Object<\/p>\n<p>2.\u00a0 JavaScript Boolean Object<\/p>\n<p>3.\u00a0 JavaScript String Object<\/p>\n<p>4.\u00a0 JavaScript Array Object<\/p>\n<p>5.\u00a0 JavaScript Date Object<\/p>\n<p>6.\u00a0 JavaScript Math Object<\/p>\n<p>7.\u00a0 JavaScript RegExp Object<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.\u00a0<\/strong><strong>JavaScript &#8211; The Number Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The <strong>Number<\/strong> object represents numerical date, either integers or floating-point numbers.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>var v1 = new Number(number);<\/p>\n<p style=\"text-align: justify\"><em>Note:<\/em> In the place of number, if you provide any non-number argument, then the argument cannot be converted into a number, it returns <strong>NaN<\/strong> (Not-a-Number).<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Number Properties:<\/strong><\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, prototype, constructor<\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0Number Methods<\/strong>:<\/p>\n<p>&nbsp;<\/p>\n<p>toExponential()<\/p>\n<p>toFixed()<\/p>\n<p>toLocaleString()<\/p>\n<p>toPrecision()<\/p>\n<p>toString()<\/p>\n<p>valueOf()<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u00a0<\/strong><strong>JavaScript &#8211; The Boolean Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The <strong>Boolean<\/strong> object represents two values, either &#8220;true&#8221; or &#8220;false&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>var v1 = new Boolean(value);<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Boolean Properties<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Constructor, prototype<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Boolean Methods<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>toSource( )<\/p>\n<p>toString( )<\/p>\n<p>valueOf( )<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.\u00a0<\/strong><strong>JavaScript &#8211; The String Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The <strong>String<\/strong> Object help us to work with strings.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>var str = new String(string);<\/p>\n<p>&nbsp;<\/p>\n<p><strong>String Properties<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>constructor , length, prototype<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>String Methods<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>charAt(), charCodeAt(), concat(), indexOf(), lastIndexOf(), localeCompare(), match(), replace()<\/p>\n<p>&nbsp;<\/p>\n<p><strong>String Object &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html &gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;Character Processing Methods&lt;\/title&gt;<\/p>\n<p>&lt;script type = &#8220;text\/javascript&#8221;&gt;<\/p>\n<p>var s = &#8220;ZEBRA&#8221;;<\/p>\n<p>var s2 = &#8220;AbCdEfG&#8221;;<\/p>\n<p>document.writeln( &#8220;&lt;p&gt;Character at i ndex 0 in &#8216;&#8221; + s + &#8220;&#8216; is &#8221; + s.charAt( 0 ) ); document.writeln( &#8220;&lt;br \/&gt;Character code at index 0 in &#8216;&#8221;+ s + &#8220;&#8216; is &#8221; + s.charCodeAt( 0 ) + &#8220;&lt;\/p&gt;&#8221; );<\/p>\n<p>document.writeln( &#8220;&lt;p&gt;'&#8221; + String.fromCharCode( 87, 79, 82, 68 ) + &#8220;&#8216; contains character codes 87, 79, 82 and 68&lt;\/p&gt;&#8221; )<\/p>\n<p>document.writeln( &#8220;&lt;p&gt;'&#8221; + s2 + &#8220;&#8216; in lowercase is &#8216;&#8221; +s2.toLowerCase() + &#8220;&#8216;&#8221; ); document.writeln( &#8220;&lt;br \/&gt;'&#8221; + s2 + &#8220;&#8216; in uppercase is &#8216;&#8221;+ s2.toUpperCase() + &#8220;&#8216;&lt;\/p&gt;&#8221; );<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;&lt;body&gt;&lt;\/body&gt;&lt;\/html&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-130 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63.png\" alt=\"\" width=\"651\" height=\"425\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63.png 651w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63-300x196.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63-225x147.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-63-350x228.png 350w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a04.\u00a0\u00a0<\/strong><strong>JavaScript &#8211; The Arrays Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The <strong>Array<\/strong> object lets you store multiple values in a single variable of same date type. The maximum length allowed for an array is 4,294,967,295.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>var fruits = new Array( &#8220;apple&#8221;, &#8220;orange&#8221;, &#8220;mango&#8221; );<\/p>\n<p>create array by simply assigning values<\/p>\n<p>var fruits = [ &#8220;apple&#8221;, &#8220;orange&#8221;, &#8220;mango&#8221; ];<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Accessing array elements<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>fruits[0] is the first element<\/p>\n<p>fruits[1] is the second element<\/p>\n<p>fruits[2] is the third element<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Array Properties<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Constructor, index, input, length, prototype<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Array Methods<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">concat(), every(), filter(), forEach(), indexOf(), join(), lastIndexOf(), map(), pop(), push() , reduce(), reduceRight(), reverse(), shift(), slice(), some(), toSource(), sort(), s plice(), toString(), unshift()<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Array Object &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html &gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;Initializing an Array with a Declaration&lt;\/title&gt; &lt;script type = &#8220;text\/javascript&#8221;&gt;<\/p>\n<p>function start()<\/p>\n<p>{<\/p>\n<p>var colors = new Array( &#8220;cyan&#8221;, &#8220;magenta&#8221;, &#8220;yellow&#8221;, &#8220;black&#8221; ); var integers1 = [ 2, 4, 6, 8 ];<\/p>\n<p>var integers2 = [ 2, , , 8 ];<\/p>\n<p>outputArray( &#8220;Array colors contains&#8221;, colors ); outputArray( &#8220;Array integers1 contains&#8221;, integers1 ); outputArray( &#8220;Array integers2 contains&#8221;, integers2 );<\/p>\n<p>}<\/p>\n<p>function outputArray( header, theArray )<\/p>\n<p>{<\/p>\n<p>document.writeln( &#8220;&lt;h2&gt;&#8221; + header + &#8220;&lt;\/h2&gt;&#8221; ); document.writeln( &#8220;&lt;table border = \\&#8221;1\\&#8221;&#8221; +&#8221;width = \\&#8221;100%\\&#8221;&gt;&#8221; ); document.writeln( &#8220;&lt;thead&gt;&lt;th width = \\&#8221;100\\&#8221; &#8221; +&#8221;align = \\&#8221;left\\&#8221;&gt;Subscript&lt;\/th&gt;&#8221; + &#8220;&lt;th align = \\&#8221;left\\&#8221;&gt;Value&lt;\/th&gt;&lt;\/thead&gt;&lt;tbody&gt;&#8221; );<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">for ( var i = 0; i &lt; theArray.length; i++ )<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">document.writeln( &#8220;&lt;tr&gt;&lt;td&gt;&#8221; + i + &#8220;&lt;\/td&gt;&lt;td&gt;&#8221; + theArray[ i ] + &#8220;&lt;\/td&gt;&lt;\/tr&gt;&#8221; ); document.writeln( &#8220;&lt;\/tbody&gt;&lt;\/table&gt;&#8221; );<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">}<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;&lt;body onload = &#8220;start()&#8221;&gt;&lt;a href=index.html&gt;back&lt;\/a&gt;&lt;\/body&gt; &lt;\/html&gt;<\/span><\/p>\n<\/div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-131 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64.png\" alt=\"\" width=\"653\" height=\"420\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64.png 653w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64-300x193.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64-225x145.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-64-350x225.png 350w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 \u00a05.\u00a0<\/strong><strong>JavaScript &#8211; The Date Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Date objects are created with the <strong>new Date( )<\/strong>. Methods allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>new Date( )<\/p>\n<p>new Date(milliseconds)<\/p>\n<p>new Date(date string)<\/p>\n<p>new Date(year,month,date [,hour, minute, second, millisecond ])<\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0Date Properties:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>constructor, prototype<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Date Methods:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Date(), getDate(), getDay(), getFullYear(), getHours(), getMilliseconds(), getMinutes(), getMonth(), getSeconds(), getTime(), getTimezoneOffset(), getUTCDate(), setMinutes(), setMonth(), setSeconds(), setTime()<\/p>\n<p>&nbsp;<\/p>\n<p><strong>6.\u00a0<\/strong><strong>JavaScript &#8211; The Math Object<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Unlike other global objects, <strong>Math<\/strong> is not a constructor. All the properties and methods of <strong>Math<\/strong> are static and can be called by using Math as an object without creating it. <strong>Syntax<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>var pi_val = Math.PI;<\/p>\n<p>var sine_val = Math.sin(30);<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Math Properties:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>E \\, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Math Methods:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">abs(), acos() , asin(), atan() , atan2() , ceil(), cos(), exp(), floor(), log(), max(), min(), pow(), sin(), random(), round(), sqrt(), tan().<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Math Object &#8211; Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&lt;html &gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>&lt;title&gt;Finding the Maximum of Three Values&lt;\/title&gt; &lt;script type = &#8220;text\/javascript&#8221;&gt;<\/p>\n<p>var input1 =<\/p>\n<p>window.prom pt( &#8220;Enter first number&#8221;, &#8220;0&#8221; );<\/p>\n<p>var input2 =<\/p>\n<p>window.prom pt( &#8220;Enter second number&#8221;, &#8220;0&#8221; );<\/p>\n<p>var input3 =window.prom<\/p>\n<p>pt( &#8220;Enter third number&#8221;, &#8220;0&#8221; );<\/p>\n<p>var value1 = parseFloat( input1 );<\/p>\n<p>var value2 = parseFloat( input2 );<\/p>\n<p>var value3 = parseFloat( input3 );<\/p>\n<p>var maxValue = maximum( value1, value2, value3 );<\/p>\n<p>document.writeln( &#8220;First number: &#8221; + value1 +&#8221;&lt;br \/&gt;Second num ber: &#8221; + value2<\/p>\n<p>+<\/p>\n<p>\\&#8221;&lt;br \/&gt;Third num ber: &#8221; + value3 +&#8221;&lt;br \/&gt;Maximum is: &#8221; + maxValue ); function maximum( x, y, z ){<\/p>\n<p><span style=\"font-size: 1em;text-align: initial\">\u00a0return Math.max( x, Math.max( y, z ) );<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">}<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/head&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;p&gt;Click Refresh (or Reload) to run the script again&lt;\/p&gt; &lt;a href=index.html&gt;back&lt;\/a&gt; &lt;\/body&gt;<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">&lt;\/html&gt;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">OUTPUT:<\/strong><\/p>\n<\/div>\n<div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-132 aligncenter\" src=\"http:\/\/csp12.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65.png\" alt=\"\" width=\"674\" height=\"454\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65.png 674w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65-300x202.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65-65x44.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65-225x152.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-content\/uploads\/sites\/60\/2018\/07\/Untitled-65-350x236.png 350w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This module explains about JavaScript Dialog boxes with examples. This module also gives an idea about arrays, functions and objects. Moreover, the module also discusses about Objects that are of two types called native\/built-in objects and user defined objects.<\/p>\n<\/div>\n<p><strong>Web Links<\/strong><\/p>\n<ul>\n<li><em>www.w3schools.com<\/em><\/li>\n<li><em>http:\/\/www.tutorialspoint.com\/javascript<\/em><\/li>\n<\/ul>\n","protected":false},"author":4,"menu_order":15,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-m-vijayalakshmi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-124","chapter","type-chapter","status-publish","hentry","contributor-dr-m-vijayalakshmi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":2,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/124\/revisions"}],"predecessor-version":[{"id":542,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/124\/revisions\/542"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapters\/124\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/pressbooks\/v2\/chapter-type?post=124"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/contributor?post=124"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp12\/wp-json\/wp\/v2\/license?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}