<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>what is javascript objects Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/what-is-javascript-objects/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/what-is-javascript-objects/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Sat, 15 Apr 2023 01:26:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>What is JavaScript Objects and JavaScript Array ?</title>
		<link>https://www.aiuniverse.xyz/javascript-objects/</link>
					<comments>https://www.aiuniverse.xyz/javascript-objects/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Tue, 04 Apr 2023 12:20:54 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[creating object in javascript]]></category>
		<category><![CDATA[javascript array]]></category>
		<category><![CDATA[javascript array constructor]]></category>
		<category><![CDATA[javascript array directly]]></category>
		<category><![CDATA[javascript array literal]]></category>
		<category><![CDATA[javascript object]]></category>
		<category><![CDATA[object constructor]]></category>
		<category><![CDATA[what is javascript objects]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=16318</guid>

					<description><![CDATA[<p>What is JavaScript Objects ? JavaScript object is an real world entity having some state and behavior (properties and method) is known as JavaScript. For example: car, <a class="read-more-link" href="https://www.aiuniverse.xyz/javascript-objects/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/javascript-objects/">What is JavaScript Objects and JavaScript Array ?</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">What is JavaScript Objects ?</h2>



<p>JavaScript object is an real world entity having some state and behavior (properties and method) is known as JavaScript. For example: car, pen, bike, chair, glass, keyboard, monitor etc.</p>



<p>JavaScript is an object-based language. Everything is an object in JavaScript. It is template based not class based. Here, we don&#8217;t create class to get the object. But, we direct create objects.</p>



<p><strong>Creating Objects in JavaScript</strong>:</p>



<p>In JavaScript, There are 3 ways to create objects.</p>



<ol class="wp-block-list">
<li>By object literal</li>



<li>By creating instance of Object directly (using new keyword)</li>



<li>By using an object constructor (using new keyword)</li>
</ol>



<ol class="wp-block-list">
<li><strong>Creating object using object literal:</strong></li>
</ol>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>object={property1:value1,property2:value2.....propertyN:valueN}  
</code></pre>



<p>The given syntax, property and value is separated by : (colon).</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
emp={id:101,name:"Abhishek Kumar",salary:50000}  
document.write(emp.id+" "+emp.name+" "+emp.salary);  
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="281" height="45" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-2.png" alt="" class="wp-image-16325"/></figure>



<p><strong>2) By creating instance of Object</strong>:</p>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>var objectname=new Object();  
</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var emp=new Object();  
emp.id=101;  
emp.name="Rahul Kumar";  
emp.salary=30000;  
document.write(emp.id+" "+emp.name+" "+emp.salary);  
&lt;/script&gt; 
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="185" height="38" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/02-1.png" alt="" class="wp-image-16327"/></figure>



<p><strong>3) By using an Object constructor</strong>:</p>



<p>Object constructor need to create function with arguments. Each argument value can be assigned in the current object by using this keyword. The&nbsp;this keyword&nbsp;refers to the current object.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
function emp(id,name,salary)
{  
this.id=id;  
this.name=name;  
this.salary=salary;  
}  
e=new emp(1001,"Rohit Kumar",50000);  
  
document.write(e.id+" "+e.name+" "+e.salary);  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="209" height="27" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-1.png" alt="" class="wp-image-16328"/></figure>



<h2 class="wp-block-heading">JavaScript Array:</h2>



<p>In JavaScript, An array is a collection of data that are stored in a variable. The values in an array can be of any type, including numbers, strings, objects, and even other arrays. Arrays are useful for storing and manipulating sets of data, such as a list of names or a series of numbers.</p>



<p>To create an array in JavaScript, you can use square brackets <code>[]</code> and separate the values with commas( , ).</p>



<p>There are 3 ways to construct array in JavaScript</p>



<ol class="wp-block-list">
<li>By array literal</li>



<li>By creating instance of Array directly (using new keyword)</li>



<li>By using an Array constructor (using new keyword)</li>
</ol>



<h2 class="wp-block-heading">1) JavaScript array literal</h2>



<p><strong>Syntax</strong>:</p>



<pre class="wp-block-code"><code>var arrayname=&#91;value1,value2.....valueN];</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var emp=&#91;"Ram","Shyam","Mohan"];  
for (i=0;i&lt;emp.length;i++){  
document.write(emp&#91;i] + "&lt;br/&gt;");  
}  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="159" height="71" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-3.png" alt="" class="wp-image-16329"/></figure>



<h2 class="wp-block-heading">2) JavaScript Array directly (new keyword)</h2>



<p><strong>Syntax:</strong> </p>



<pre class="wp-block-code"><code>var arrayname=new Array();  
</code></pre>



<p>Here,&nbsp;new keyword&nbsp;is used to create instance of array.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var i;  
var emp = new Array();  
emp&#91;0] = "Rohit";  
emp&#91;1] = "Mohit";  
emp&#91;2] = "Urfi";  
  
for (i=0;i&lt;emp.length;i++)
{  
document.write(emp&#91;i] + "&lt;br&gt;");  
}  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="169" height="66" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/00.png" alt="" class="wp-image-16330"/></figure>



<h2 class="wp-block-heading">3) JavaScript array constructor (new keyword):</h2>



<p>The example of creating object by array constructor is given below-</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var emp=new Array("Rahul","Rohit","Smith");  
for (i=0;i&lt;emp.length;i++)
{  
document.write(emp&#91;i] + "&lt;br&gt;");  
}  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="126" height="70" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-2.png" alt="" class="wp-image-16331"/></figure>



<h2 class="wp-block-heading">JavaScript Array Methods:</h2>



<p>Arrays have many built-in methods for manipulating and iterating over the elements.</p>



<p><strong>Some of the most commonly used array methods are:</strong></p>



<ul class="wp-block-list">
<li><strong>length</strong>&nbsp;&#8211; This method returns the number of elements in an array. For example, the following code will return 3:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
console.log(myArray.length);
</code></pre>



<ul class="wp-block-list">
<li><strong>push</strong>&nbsp;&#8211; This method is used to add an element to the end of an array. For example, the following code will add the element &#8220;World&#8221; to the end of the array:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
myArray.push("World");
console.log(myArray); // &#91;1, "Hello", &#91;2, 3], "World"]</code></pre>



<ul class="wp-block-list">
<li><strong>pop</strong>&nbsp;&#8211; This method is used to remove the last element of an array. For example, the following code will remove the last element (&#8220;World&#8221;) from the array:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3], "World"];
myArray.pop();
console.log(myArray); // &#91;1, "Hello", &#91;2, 3]]
</code></pre>



<ul class="wp-block-list">
<li><strong>shift</strong>&nbsp;&#8211; This method is used to remove the first element of an array. For example, the following code will remove the first element (1) from the array:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
myArray.shift();
console.log(myArray); // &#91;"Hello", &#91;2, 3]]
</code></pre>



<ul class="wp-block-list">
<li><strong>unshift</strong>&nbsp;&#8211; This method is used to add an element to the beginning of an array. For example, the following code will add the element 0 to the beginning of the array:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
myArray.unshift(0);
console.log(myArray); // &#91;0, 1, "Hello", &#91;2, 3]]
</code></pre>



<ul class="wp-block-list">
<li><strong>slice</strong>&nbsp;&#8211; This method is used to extract a portion of an array. For example, the following code will extract the elements from index 1 to 2 (exclusive):</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
console.log(myArray.slice(1, 2)); // &#91;"Hello"]
</code></pre>



<ul class="wp-block-list">
<li><strong>splice</strong>&nbsp;&#8211; This method is used to add or remove elements from an array. For example, the following code will remove the element at index 1 and add the elements &#8220;Hello World&#8221; and [4, 5] at index 1:</li>
</ul>



<pre class="wp-block-code"><code>var myArray = &#91;1, "Hello", &#91;2, 3]];
myArray.splice(1, 1, "Hello World", &#91;4, 5]);
console.
</code></pre>



<h2 class="wp-block-heading">JavaScript String:</h2>



<p>It is one of the most important concept of JavaScript, A string is a sequence of characters enclosed within single quotes or double quotes. For example, the following are valid strings in JavaScript:</p>



<pre class="wp-block-code"><code>let strName = 'Hello, world!';
let strName = "Hello, world!";
</code></pre>



<p>There are 2 ways to create string in JavaScript</p>



<ol class="wp-block-list">
<li>By string literal</li>



<li>By string object (using new keyword)</li>
</ol>



<ol class="wp-block-list">
<li><strong>By string literal:</strong></li>
</ol>



<p>String literal is created using single quotes or double quotes.</p>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>let strName = 'Hello, world!';
let strName = "Hello, world!";</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var str='This is the example of string literal';  
var str1="This is the example of string literal";
document.write(str + "&lt;br&gt;"); 
document.write(str1);  

&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="255" height="71" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-4.png" alt="" class="wp-image-16336"/></figure>



<p><strong>2. By string object (using new keyword):</strong></p>



<p>new keyword&nbsp;is used to create instance of string.</p>



<p><strong>Syntax:</strong></p>



<pre class="wp-block-code"><code>var strName=new String("string literal");  </code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var strName=new String("hello javascript string");  
document.write(strName);  
&lt;/script&gt; 
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="187" height="40" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-2.png" alt="" class="wp-image-16337"/></figure>



<h2 class="wp-block-heading">String Methods: </h2>



<p>String have many in-built methods for manipulating the elements.</p>



<p><strong>Some of the most commonly used string methods are:</strong></p>



<ul class="wp-block-list">
<li><strong>length</strong>()&nbsp;&#8211; This method returns the number of characters in a string. For example, the following code will return 11:</li>
</ul>



<pre class="wp-block-code"><code>var str = "Hello World";
console.log(str.length);</code></pre>



<ul class="wp-block-list">
<li><strong>charAt(</strong>Index<strong>) </strong>&#8211; This method returns the character at the given index. For example, the following code will return c:</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var str="Welcome";  
document.write(str.charAt(3));  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>concat(</strong>str<strong>) </strong>&#8211; This method concatenates or joins two strings. For example, the following code will return &#8211; Welcome To Cotocus</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="Welcome ";  
var s2="To Cotocus";  
var s3=s1.concat(s2);  
document.write(s3);  // Welcome To Cotocus
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>indexOf</strong> (index)&nbsp;&#8211; This method is used to find the index of a specific character or substring in a string. For example, the following code will return 8:</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="Welcome to aiuniverse.xyz";  
var n=s1.indexOf("to");  
document.write(n);  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>split() Method</strong>: </li>
</ul>



<p>It splits a string into substring array, then returns that newly created array.</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
    &lt;script&gt;  
        var str="Welcome to aiuniverse.xyz";  
        document.write(str.split(" ")); //splits the given string.  
    &lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>trim() Method</strong>: This method removes leading and trailing whitespaces from the string.</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="     Maruti Cotocus      ";  
var s2=s1.trim();  
document.write(s2);  // remove before space and after space
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>toUpperCase() Method</strong>: These methods are used to convert a string to uppercase letters.</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="JavaScript toUpperCase Example by Maruti";  
var s2=s1.toUpperCase();  
document.write(s2);  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="410" height="39" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-2.png" alt="" class="wp-image-16340" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-2.png 410w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-2-300x29.png 300w" sizes="auto, (max-width: 410px) 100vw, 410px" /></figure>



<ul class="wp-block-list">
<li><strong>toLowerCase() Method</strong>: These methods are used to convert a string to lowercase letters.</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="JavaScript toUpperCase Example by Maruti";  
var s2=s1.toLowerCase();  
document.write(s2);  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="300" height="30" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/00-1.png" alt="" class="wp-image-16341"/></figure>



<ul class="wp-block-list">
<li><strong>slice(beginIndex, endIndex) Method</strong>&#8211; This method is used to extract a portion of a string.</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var s1="MarutiKumar";  
var s2=s1.slice(3,6);  
document.write(s2);  //uti
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<ul class="wp-block-list">
<li><strong>replace()&nbsp;</strong>&#8211; This method is used to replace a specific character or substring in a string. For example, the following code will return &#8220;Hello Universe&#8221;:</li>
</ul>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;script&gt;
var str="Welcome Cotocus";
document.writeln(str.replace("Cotocus","Maruti"));
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="138" height="29" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/0000.png" alt="" class="wp-image-16342"/></figure>



<h2 class="wp-block-heading">Date Object:</h2>



<p>In JavaScript, Date object has a in-built object that can be used to work with dates and times.</p>



<p>You can use 4 variant of Date constructor to create date object.</p>



<ol class="wp-block-list">
<li>Date()</li>



<li>Date(milliseconds)</li>



<li>Date(dateString)</li>



<li>Date(year, month, day, hours, minutes, seconds, milliseconds)</li>
</ol>



<ol class="wp-block-list">
<li><strong>Date()</strong>: Date object is used to prints current date and time both.</li>
</ol>



<p><strong>Example:</strong> </p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
Current Date and Time: &lt;span id="txt"&gt;&lt;/span&gt;  
&lt;script&gt;  
var today=new Date();  
document.getElementById('txt').innerHTML=today;  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p>Another Example:  Print date/month/year.</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
    &lt;script&gt;  
        var date=new Date();  
        var day=date.getDate();  
        var month=date.getMonth()+1;  
        var year=date.getFullYear();  
        document.write("&lt;br&gt;Date is: "+day+"/"+month+"/"+year);  
        &lt;/script&gt;   
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



<p><strong>Current Time Example</strong>:</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
Current Time: &lt;span id="txt"&gt;&lt;/span&gt;
&lt;script&gt;
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<h2 class="wp-block-heading">JavaScript Math:</h2>



<p>In JavaScript, Math is a built-in object in JavaScript that provides mathematical functions and constants for performing mathematical operations such as trigonometry, logarithms, etc. It provides a set of methods and properties that allow developers to perform complex mathematical calculations easily and efficiently.</p>



<p><strong>most commonly used functions in the&nbsp;<code>Math</code>&nbsp;object is-</strong></p>



<ol class="wp-block-list">
<li><strong>Math.random()</strong></li>
</ol>



<p>Math.random() method returns the random number between &nbsp;0 (inclusive) and 1 (exclusive).&nbsp;This function can be used to generate random numbers for various purposes such as games, simulations, and other applications.</p>



<p><strong>For Example:</strong></p>



<p></p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

Random Number is: &lt;span id="p2"&gt;&lt;/span&gt;    
&lt;script&gt;    
document.getElementById('p2').innerHTML=Math.random();    
&lt;/script&gt;   

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong> </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="298" height="40" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/01.png" alt="" class="wp-image-16347"/></figure>



<p><strong>2. Math.pow(m,n)</strong></p>



<p>Math.pow(m,n) method returns the m to the power of n that is m<sup>n</sup>.</p>



<p><strong>For Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

5 to the power of 3 is: &lt;span id="p5"&gt;&lt;/span&gt;    
&lt;script&gt;    
document.getElementById('p5').innerHTML=Math.pow(5,3);    
&lt;/script&gt;    

&lt;/body&gt;
&lt;/html&gt;</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="199" height="39" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/22.png" alt="" class="wp-image-16348"/></figure>



<p><strong>3. Math.sqrt(n)</strong></p>



<p>This method is used to returns the square root of the given number.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

Square Root of 625 is: &lt;span id="p1"&gt;&lt;/span&gt;    
&lt;script&gt;    
document.getElementById('p1').innerHTML=Math.sqrt(625);    
&lt;/script&gt;   

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="171" height="30" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-5.png" alt="" class="wp-image-16349"/></figure>



<p><strong>4. Math.floor(n)</strong></p>



<p>This method is used&nbsp;to round a number down to the nearest integer. For example 9 for 9.7, 5 for 5.9 etc.</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

Floor of 4.6 is: &lt;span id="p4"&gt;&lt;/span&gt;    
&lt;script&gt;    
document.getElementById('p4').innerHTML=Math.floor(4.6);    
&lt;/script&gt;  

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="137" height="36" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/image.png" alt="" class="wp-image-16350"/></figure>



<p><strong>5. Math.ceil(n)</strong></p>



<p>This method is used to rounds a number up to the nearest integer. For example 4 for 3.7, 6 for 5.9 etc.</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

Ceil of 7.6 is: &lt;span id="p5"&gt;&lt;/span&gt;    
&lt;script&gt;    
document.getElementById('p5').innerHTML=Math.ceil(7.6);    
&lt;/script&gt;    

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Output:</strong></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="127" height="33" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/1.png" alt="" class="wp-image-16353"/></figure>



<p><strong>6. Math.abs(n)</strong></p>



<p>This method returns the absolute value for the given number. For example 5 for -5.6 &amp; 6 for -6.6 etc.</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

Absolute value of -4 is: &lt;span id="p8"&gt;&lt;/span&gt;      
&lt;script&gt;      
document.getElementById('p8').innerHTML=Math.abs(-4);      
&lt;/script&gt; 

&lt;/body&gt;
&lt;/html&gt;
</code></pre>



<p><strong>Example:</strong> </p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="182" height="36" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/55.png" alt="" class="wp-image-16354"/></figure>



<h2 class="wp-block-heading">Number Object:</h2>



<p>In JavaScript, a number object is a built-in object that provides a number of properties and methods for working with numeric values. The&nbsp;<code>Number</code>&nbsp;object can be used to convert a value to a number, perform mathematical operations, and format numbers for display.</p>



<p><strong>Most commonly used methods of the&nbsp;<code>Number</code>&nbsp;object is</strong>&#8211;</p>



<ul class="wp-block-list">
<li><strong>Number()</strong>: This method is used to convert a value to a number, This function can be used to convert strings, Booleans, and other types of values to numbers.</li>
</ul>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>console.log(Number("3.14"));
// Output: 3.14
console.log(Number(true));
// Output: 1
</code></pre>



<ul class="wp-block-list">
<li><strong>toFixed()</strong>: This method to format a number with a specific number of decimal places:</li>
</ul>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>const numObj = new Number(10.12345);
console.log(numObj.toFixed(2)); // Output: "10.12"
</code></pre>



<ul class="wp-block-list">
<li><strong>valueOf():</strong> convert a number object to a primitive numeric value using the <code>valueOf()</code> method:</li>
</ul>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>const numObj = new Number(10);
const num = numObj.valueOf();
console.log(num); // Output: 10
</code></pre>



<h2 class="wp-block-heading">Boolean:</h2>



<p>Boolean&nbsp;object is used to represents value in two states:&nbsp;true&nbsp;or&nbsp;false. The&nbsp;<code>Boolean</code>&nbsp;object can be used to create Boolean values and perform logical operations, such as and, or, and not.</p>



<p>A Boolean value can be created by using the&nbsp;<code>Boolean()</code>&nbsp;function or by assigning a value of true or false to a variable.</p>



<pre class="wp-block-code"><code>var isTrue = Boolean(1);
console.log(isTrue); // Output: true
var isFalse = Boolean(0);
console.log(isFalse); // Output: false
</code></pre>
<p>The post <a href="https://www.aiuniverse.xyz/javascript-objects/">What is JavaScript Objects and JavaScript Array ?</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/javascript-objects/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
