<?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 variable Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/what-is-variable/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/what-is-variable/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Sat, 15 Apr 2023 01:33:07 +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>JavaScript Basics</title>
		<link>https://www.aiuniverse.xyz/javascript-basics/</link>
					<comments>https://www.aiuniverse.xyz/javascript-basics/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Mon, 03 Apr 2023 13:05:14 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[advantage of javascript comments]]></category>
		<category><![CDATA[data types]]></category>
		<category><![CDATA[JavaScript Basic]]></category>
		<category><![CDATA[javascript comment]]></category>
		<category><![CDATA[javascript global variable]]></category>
		<category><![CDATA[javascript local variable]]></category>
		<category><![CDATA[javascript loops]]></category>
		<category><![CDATA[js if-else statement]]></category>
		<category><![CDATA[non-primitive data type]]></category>
		<category><![CDATA[primitive data types]]></category>
		<category><![CDATA[switch case]]></category>
		<category><![CDATA[type of javascript comment]]></category>
		<category><![CDATA[what is operatior]]></category>
		<category><![CDATA[what is variable]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=16308</guid>

					<description><![CDATA[<p>JavaScript Comment: In JavaScript, comments are used to add information about the code, that are ignored by the browser or interpreter. Advantage of JavaScript comments: The main <a class="read-more-link" href="https://www.aiuniverse.xyz/javascript-basics/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/javascript-basics/">JavaScript Basics</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">JavaScript Comment:</h1>



<p>In JavaScript, comments are used to add information about the code, that are ignored by the browser or interpreter. </p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="903" height="212" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/javascript-comment.webp" alt="" class="wp-image-16456" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/javascript-comment.webp 903w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/javascript-comment-300x70.webp 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/javascript-comment-768x180.webp 768w" sizes="(max-width: 903px) 100vw, 903px" /></figure>



<p><strong>Advantage of JavaScript comments:</strong></p>



<p>The main advantage of comments are-</p>



<ol class="wp-block-list">
<li><strong>Easy to understand the code</strong>:&nbsp;It can be used to elaborate the code so that end user can easily understand the code.</li>



<li><strong>To avoid the unnecessary code</strong>:&nbsp;It can also be used to avoid the code being executed. Sometimes, we add the code to perform some action. But after sometime, there may be need to disable the code. In such case, it is better to use comments.</li>
</ol>



<h2 class="wp-block-heading">Types of JavaScript Comments</h2>



<p>There are two types of comments in JavaScript.</p>



<ol class="wp-block-list">
<li><strong>Single-line comments:</strong> They begin with two forward slashes (//) and continue until the end of the line.</li>
</ol>



<p>Example1:</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
// It is single line comment  
document.write("hello aiuniverse.xyz");  
&lt;/script&gt; 
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



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



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-1-1024x576.png" alt="" class="wp-image-16309" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-1-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-1-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-1-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Example2:</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var a=10;  
var b=20;  
var c=a+b;//It adds values of a and b variable  
document.write(c);//prints sum of 10 and 20  
&lt;/script&gt;   
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



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



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-1-1024x576.png" alt="" class="wp-image-16310" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-1-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-1-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-1-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/2-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>2. <strong>Multi-line comments:</strong> They begin with /* and end with */. Anything between these characters will be ignored by the browser or interpreter.</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
/* It is multi line comment.  
It will not be displayed */  
document.write("example of javascript multiline comment");  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



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



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-1024x576.png" alt="" class="wp-image-16311" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/3.png 1366w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">What is Variables ?</h2>



<p>Variable is an essential part of any programming language, It is used to stored data. They allow you to store, retrieve, and manipulate data in your programs. There are two types of variables in JavaScript : Local variable , Global variable.</p>



<p>Some rules for declaring a JavaScript variable (also known as identifiers).</p>



<ul class="wp-block-list">
<li>Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.</li>



<li>After first letter we can use any digits (0 to 9), for example value1.</li>



<li>JavaScript variables are case sensitive, for example x and X are different variables.</li>
</ul>



<p>Variables are declared using the <strong><code>var</code>, <code>let</code>,</strong> or <strong><code>const</code> </strong>keyword followed by the variable name.</p>



<p>For example:</p>



<pre class="wp-block-code"><code>// Declaring a variable using var
var message = "Hello World!";

// Declaring a variable using let
let age = 20;

// Declaring a variable using const
const PI = 3.14;
</code></pre>



<p>Where, <strong>&#8220;var&#8221;</strong> keyword followed by the name of the variable and &nbsp;<strong>&#8220;let&#8221;</strong> and <strong>&#8220;const&#8221;</strong> keywords to declare variables.&nbsp;</p>



<p>Once a variable is declared, its value can be assigned or updated by using the <code>=</code> operator:</p>



<pre class="wp-block-code"><code>// Assigning a value to a variable
var x;
x = 20;

// Updating the value of a variable
var y = 6;
y = y + 1;
</code></pre>



<p>Variables can hold various types of values, including numbers, strings, Boolean values, arrays, objects, and more.</p>



<pre class="wp-block-code"><code>// Example of variables holding different types of values
var num = 12;
var greeting = "Hello";
var isTrue = true;
var myArray = &#91;1, 2, 3];
var person = {name: "Rohit", age: 25};
</code></pre>



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



<p>A JavaScript local variable is declared inside block (function). It is accessible within the function or block only. For example:</p>



<pre class="wp-block-code"><code>&lt;script&gt;  
function abc(){  
var x=20;  //local variable  
}  
&lt;/script&gt; </code></pre>



<p><strong>Or</strong></p>



<pre class="wp-block-code"><code>&lt;script&gt;  
If(10&lt;15){  
var y=30;  //JavaScript local variable  
}  
&lt;/script&gt;</code></pre>



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



<p>A variable i.e. declared outside the function or declared with window object is known as global variable. A&nbsp;JavaScript global variable&nbsp;is accessible from any function. For example:</p>



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var data=500; //gloabal variable  
function a(){  
document.writeln(data);  
}  
function b(){  
document.writeln(data);  
}  
a();//calling JavaScript function
b();
  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;
</code></pre>



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



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/4-1024x576.png" alt="" class="wp-image-16313" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/4-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/4-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/4-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/4.png 1366w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Data Types</h2>



<p>JavaScript provides different&nbsp;data types&nbsp;to hold different types of values. There are two types of data types in JavaScript.</p>



<ol class="wp-block-list">
<li>Primitive data type</li>



<li>Non-primitive (reference) data type</li>
</ol>



<p><strong>Primitive data type</strong>:</p>



<p>There are five types of primitive data types in JavaScript. </p>



<ol class="wp-block-list">
<li><strong>Number:</strong> This data type is used to represent numeric values, including integers and floating-point numbers. (e.g. 10, 3.14)</li>



<li><strong>String:</strong> This data type is used to represent text values, enclosed in single or double quotes. (e.g. &#8220;hello&#8221;, &#8216;world&#8217;)</li>



<li><strong>Boolean:</strong> This data type is used to represent true or false values. (e.g. true, false)</li>



<li><strong>Undefined:</strong> This data type is used to represent a variable that has been declared but not assigned a value. </li>



<li><strong>Null:</strong> This data type has only one value, null, which represents the absence of any object value.</li>
</ol>



<p><strong>Non-Primitive data type:</strong></p>



<p>The non-primitive data types are as follows:</p>



<ol class="wp-block-list">
<li> <strong>Object:</strong> This data type is used to represent complex data structures, including arrays, functions, and objects. (e.g. { name: &#8220;John&#8221;, age: 30 })</li>



<li><strong>Array:</strong> (e.g. [1, 2, 3])</li>
</ol>



<h2 class="wp-block-heading">JavaScript Operators and Expressions</h2>



<h2 class="wp-block-heading">What is Operators ?</h2>



<p>Operators in JavaScript are symbols that perform specific operations on one or more operands (values or variables). For example, the addition operator (+) adds two operands together and the assignment operator (=) assigns a value to a variable.</p>



<p>There are different types of operators in JavaScript, including:</p>



<ol class="wp-block-list">
<li>Arithmetic Operators</li>



<li>Comparison (Relational) Operators</li>



<li>Bitwise Operators</li>



<li>Logical Operators</li>



<li>Assignment Operators</li>



<li>Conditional (ternary) operator</li>
</ol>



<ol class="wp-block-list">
<li><strong>Arithmetic Operators:</strong> Used to perform arithmetic operations on numbers.  Examples: + (addition), &#8211; (subtraction), * (multiplication), / (division), % (modulus), ++ (increment), and &#8212; (decrement).</li>



<li><strong>Comparison Operators:</strong> It is used to compare two values or variables.  Examples: == (equal to), != (not equal to), === (strictly equal to), !== (strictly not equal to), &gt; (greater than), &lt; (less than), &gt;= (greater than or equal to), and &lt;= (less than or equal to).</li>



<li><strong>Bitwise Operators: </strong>Used to perform bitwise operations on numbers. Examples: &amp; (bitwise and), | (bitwise or), ^ (bitwise exclusive or), ~ (bitwise not), &lt;&lt; (left shift), and &gt;&gt; (right shift).</li>



<li><strong>Logical Operators:</strong> It is used to combine two or more conditions. Examples: &amp;&amp; (logical and), || (logical or), and ! (logical not).</li>



<li><strong>Assignment Operators:</strong> It is used to assign values to variables. Examples: = (assignment), += (add and assign), -= (subtract and assign), *= (multiply and assign), /= (divide and assign), and %= (modulus and assign).</li>



<li><strong>Conditional (Ternary) Operator:</strong> It is used to assign a value to a variable based on a condition. Example: variable = (condition) ? value1 : value2;</li>
</ol>



<h2 class="wp-block-heading">What is Expressions ?</h2>



<p>Expressions are combinations of values, variables, and operators that produce a result. For example:</p>



<pre class="wp-block-code"><code>2 + 2 // produces the value 4
"Hello, " + "world!" // produces the value "Hello, world!"
true &amp;&amp; false // produces the value false
Math.Pow(2, 3) // produces the value 8
</code></pre>



<h2 class="wp-block-heading">JS If-Else Statement:</h2>



<p>The&nbsp;if-else statement&nbsp;is used&nbsp;<em>to execute the code whether condition is true or false</em>. There are three forms of if statement in JavaScript.</p>



<ol class="wp-block-list">
<li>If Statement</li>



<li>If else statement</li>



<li>If else if statement</li>
</ol>



<ol class="wp-block-list">
<li><strong>If Statement:</strong></li>
</ol>



<p>The &#8220;if&#8221; statement in JavaScript is used to execute a block of code if a certain condition is true.</p>



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



<pre class="wp-block-code"><code>if(expression)
{  
//code to be executed if the condition is true
} 
}  
</code></pre>



<p>2. <strong>If else statement</strong>:</p>



<p>The &#8220;if&#8221; statement in JavaScript is used to execute a block of code if a certain condition is true. The &#8220;else&#8221; clause is used to execute a block of code if the condition is false.</p>



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



<pre class="wp-block-code"><code>if (condition) 
{
  // code will be executed if the condition is true
}
else 
{
  // code will be executed if the condition is false
}
</code></pre>



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



<pre class="wp-block-code"><code>let number = 5;

if (number % 2 == 0) 
{
  console.log("The number is even.");
} else {
  console.log("The number is odd.");
}
</code></pre>



<p>3.<strong> If else if statement</strong>: (If else ladder):</p>



<pre class="wp-block-code"><code>if(expression1)
{  
//content will be evaluated if expression1 is true  
}  
else if(expression2)
{  
//content will be evaluated if expression2 is true  
}  
else if(expression3)
{  
//content will be evaluated if expression3 is true  
}  
else
{  
//content will be evaluated if no expression is true  
}  </code></pre>



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



<pre class="wp-block-code"><code>&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
var a=30;  
if(a==20)
{  
document.write("a is equal to 20");  
}  
else if(a==25)
{  
document.write("a is equal to 25");  
}  
else if(a==20)
{  
document.write("a is equal to 30");  
}  
else
{  
document.write("a is not equal to 20, 25 or 30");  
}  
&lt;/script&gt;  
&lt;/body&gt;
&lt;/html&gt;</code></pre>



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



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture01-1024x576.png" alt="" class="wp-image-16314" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture01-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture01-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture01-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/Capture01.png 1366w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



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



<p>The &#8220;switch&#8221; statement in JavaScript is another control structure, &nbsp;It is used&nbsp;to execute one code from multiple expressions. It is just like &nbsp;&#8220;if-else ladder&#8221;&nbsp; statement&nbsp;when you have multiple conditions to check against a single value.</p>



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



<pre class="wp-block-code"><code>switch (expression) 
{
  case value1:
    // code will be executed if expression == value1
    break;
  case value2:
    // code will be executed if expression == value2
    break;
  …
  default:
    // code will be executed if expression does not match any of the values
}</code></pre>



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



<p>In JavaScript, Loop statements to execute a block of code repeatedly. There are several type of loop statements:-</p>



<ol class="wp-block-list">
<li><strong>for loop:</strong> The for loop repeats a block of code a specified number of times. It has three parts: initialization, condition, and increment/decrement.</li>
</ol>



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



<pre class="wp-block-code"><code>for (initialization; condition; increment/decrement) 
{
  // code will be executed
}
</code></pre>



<p>Example:</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;script&gt;  
for (i=1; i&lt;=10; i++)  
{  
document.write(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-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-1024x576.png" alt="" class="wp-image-16315" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-1024x576.png 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-300x169.png 300w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11-768x432.png 768w, https://www.aiuniverse.xyz/wp-content/uploads/2023/04/11.png 1366w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ol class="wp-block-list" start="2">
<li><strong>while loop</strong>: The while loop repeats a block of code as long as the specified condition is true.</li>
</ol>



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



<pre class="wp-block-code"><code>while (condition) 
{
  // code to be executed
}
</code></pre>



<p>3. <strong>do&#8230;while loop</strong>: The do&#8230;while loop is similar to the while loop, except that it always executes the code block at least once before checking the condition.</p>



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



<pre class="wp-block-code"><code>do {
  // code to be executed
} while (condition);
</code></pre>



<ol class="wp-block-list" start="4">
<li><strong>forEach loop</strong>: The forEach loop is used to iterate over an array or other iterable object and execute a function for each element.</li>
</ol>



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



<pre class="wp-block-code"><code>array.forEach(function(item, index) 
{
  // code to be executed
});
</code></pre>



<ol class="wp-block-list" start="5">
<li><strong>For-in loop</strong>: The for-in loop is used to iterate over the properties of an object. </li>
</ol>



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



<pre class="wp-block-code"><code>for (variable in object) 
{
  // code to be executed
}
</code></pre>



<p>6<strong>. For-of loop:</strong> The for-of loop is used to iterate over the values of an iterable object, such as an array or a string. </p>



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



<pre class="wp-block-code"><code>for (variable of object) 
{
  // code to be executed
}
</code></pre>



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



<p>JavaScript functions are blocks of code that can be defined and executed whenever needed.&nbsp;A function in JavaScript is a reusable block of code that performs a specific task. You can call a function multiple times, and it will execute the same set of instructions each time. Functions can also take arguments and return a value.</p>



<p>Example of a function that takes two arguments (num1 and num2) and returns their sum:</p>



<pre class="wp-block-code"><code>function addNumbers(num1, num2) 
{
  return num1 + num2;
}
</code></pre>



<p>To call this function and pass in two numbers, you would do something like this:</p>



<pre class="wp-block-code"><code>let result = addNumbers(5, 10);
console.log(result); // Output: 15
</code></pre>



<h2 class="wp-block-heading"><br></h2>
<p>The post <a href="https://www.aiuniverse.xyz/javascript-basics/">JavaScript Basics</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/javascript-basics/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
