<?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>javascript Archives - Postnidea</title>
	<atom:link href="https://www.postnidea.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.postnidea.com/category/javascript/</link>
	<description>Programming Blog, Tutorials, jQuery, Ajax, PHP, MySQL and Demos</description>
	<lastBuildDate>Tue, 27 May 2025 09:13:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.8</generator>

<image>
	<url>https://www.postnidea.com/wp-content/uploads/2019/08/favicon.ico</url>
	<title>javascript Archives - Postnidea</title>
	<link>https://www.postnidea.com/category/javascript/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>A Refreshing Dive into JavaScript ES6 Concepts</title>
		<link>https://www.postnidea.com/a-refreshing-dive-into-javascript-es6-concepts/</link>
		
		<dc:creator><![CDATA[Rakesh Kumar]]></dc:creator>
		<pubDate>Wed, 06 Nov 2024 11:38:33 +0000</pubDate>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Jquery]]></category>
		<guid isPermaLink="false">https://www.postnidea.com/?p=269</guid>

					<description><![CDATA[<p>JavaScript ES6 concepts and principles are fundamental. Nowadays new modern javascript libraries and frameworks use these concepts. ES6 concepts, covering [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/a-refreshing-dive-into-javascript-es6-concepts/">A Refreshing Dive into JavaScript ES6 Concepts</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>JavaScript ES6 concepts and principles are fundamental. Nowadays new modern javascript libraries and frameworks use these concepts. ES6 concepts, covering variables and data types, functions, arrays and objects, control flow and loops, error handling, scope and closures, and DOM manipulation. Each section provides an in-depth explanation with examples to help you understand these fundamental aspects of JavaScript. Nowadays React <a href="https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/" target="_blank" rel="noreferrer noopener">Angular</a> and other javascript technologies are using these core practices. By mastering the fundamentals of JavaScript ES6, you&#8217;ll be equipped with the knowledge and skills to write clean, maintainable code and tackle more advanced JavaScript concepts with confidence. So, let&#8217;s dive in and unlock the power of JavaScript ES6 together!</p>



<h2 class="wp-block-heading">Difference between var, let &amp; const</h2>



<p>By using <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">var</mark></code> old way of defining variables. But javascript still maintains this type of syntax so, that old written code can also be executed and run by language because after an update each code updates a crucial thing.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>var p_name = &quot;jhon&quot;;
console.log(p_name); // will print jhon
p_name = &quot;Rahul&quot;;
console.log(p_name); // will print Rahul
var p_name=&quot;Ramesh&quot;;
console.log(p_name);</code></pre></div>



<p>In the above code, you can see it different way of defining var. The var is globally scoped so, you can define its top, and can be modified anywhere wherever required let me explain by example.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>var username = &quot;Jhon&quot;;
var age = 24;
if (age &gt; 23) {
    var usename = &quot;Mosh&quot;; 
}
console.log(usename) // Will print &quot;Mosh&quot;</code></pre></div>



<p>In the above example, you can see that we have defined a username and in the if statement block is modified and can be accessed outside the block and able to print it. But in the case of let and const this will not happen because both are block scoped so, will able to access within the block the same thing let me explain to you by example.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>let username = &quot;Jhon&quot;;
let age = 24;
if (age &gt; 23) {
     let usename = &quot;Mosh&quot;; 
}
console.log(usename) // Will print usename is not defined</code></pre></div>



<p>If we print the username then will throw an error because we again define in if block and it is block-scoped and their scope ends there if we do not again initialize with let in if block then will not throw an error. You can initialize a single time and can modify the value anywhere.</p>



<p>The const works the same as the variable but the main difference is that their value can not be modified within the block or outside the block in this datatype you can add value a single time and will same throughout the execution.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const fullname = &quot;Rakesh Kumar&quot;;
console.log(fullname); // Will print Rakesh Kumar
fullname = &quot;Mahesh&quot;; // TypeError: Assignment to constant variable.</code></pre></div>



<h2 class="wp-block-heading">Arrow function in JavaScript ES6</h2>



<p>It&#8217;s the same as a normal function that we create we create as usual like below let&#8217;s take an example of the addition of two numbers this function will add two provided numbers and return it.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>function add(n1, n2){
	return n1+n2;
}
console.log(add(5,2)); // Will print 7</code></pre></div>



<p>In JavaScript, an arrow function is a shortcut for writing functions. Compared to a conventional function expression, it is syntactically more compact and has several specific features, particularly with regard to this binding. This can be written by using => (&#8220;fat arrow&#8221;) syntax same function converts into an arrow function. There is also no difference in calling.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const add = (a, b) =&gt; {
  return  a + b;
};
console.log(add(5,2)); // Will print 7</code></pre></div>



<p>For more convenience, we can also remove &#8220;{}&#8221; from the function definition. But there is a different calling for single and multiple parameters let see the example for both and single and multiple parameters.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const add = (a, b) =&gt; a + b;
console.log(add(5,2)); // Will print 7

const doubler = x =&gt; 2 * x;
console.log(doubler(5)); // Will print 10

const say = () =&gt; &#39;Say Hello&#39;;
console.log(say()); // Will Say Hello</code></pre></div>



<p><strong>use case for arrow function:</strong><br>This implementation in short inline actions, like array operations (map, filter, reduce)</p>



<h4 class="wp-block-heading">Differences from Regular Functions:</h4>



<p><strong>Lexical </strong><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color has-ast-global-color-7-color">this</mark><strong> Binding:</strong> Arrow functions don&#8217;t have a context of their own. Rather, they inherit this from the global scope or surrounding function. When you wish to maintain the surrounding scope&#8217;s value during callbacks, this is quite helpful.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>function counter() {
  this.increment = 0;
  setInterval(() =&gt; {
    this.increment++; // &#39;this&#39; refers to the counter instance
  }, 1000);
}
let c = new counter();
console.log(c.age); // will print 0</code></pre></div>



<p>In the above example, you can see it will print 0 because of this reference to global scope. If we<br>console.log(this.increment)<br>within the setInterval curly braces inside then will print. So, it&#8217;s globally scoped and block context.</p>



<p><strong>Cannot be used as Constructors:</strong><br>The arrow function can not be used as a constructor you can see in the above example like<br>let c = new counter();<br>But if we can try with same thing with the arrow function will print the below error.<br>TypeError: counter is not a constructor</p>



<p><strong>Implicit return:</strong><br>When creating a single argument function then return the keyword not required by default omitted.<br>const doubler = x => 2 * x;<br>In this example, you can see I have not used the return keyword.</p>



<h4 class="wp-block-heading">Use Cases of arrow function in JavaScript ES6</h4>



<p>The best implementation of the arrow function you can see in map, filter, and reduce.</p>



<h2 class="wp-block-heading">Modules in JavaScript ES6</h2>



<p>JavaScript modules were established through the ES6 module syntax, providing a standardized approach for importing and exporting code across different files. This modularity enables programmers to organize their code more effectively and facilitates the sharing of functionality among various components of an application.</p>



<p>To explain the module let&#8217;s take an example that already stated that modular means we can write code in different files and use any place so let me create three files.<br><code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">user.js // contain user information<br>address.js //will contain details related to address<br>main.js // it's the final file in which call both above file code</mark></code></p>



<h3 class="wp-block-heading">Exporting from a Module</h3>



<h4 class="wp-block-heading"><strong>Default Export</strong>:</h4>



<p>Now I have created first file <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">user.js</mark></code> in which you can see it I have saved the user information in variable user and at the end I have added the line<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-ast-global-color-6-color"> </mark><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">export default user</mark><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-ast-global-color-6-color">;</mark></code> this code provides the ability to use method, variable, etc in another file. In default export, we can export only the single class, method, and variable in another file by import.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>// Filename : user.js 
//---------------------------
const user = {
    username:&quot;Jhon&quot;,
    email:&quot;john@gmail.com&quot;
}
export default user;</code></pre></div>



<h4 class="wp-block-heading"><strong>Named Exports</strong>:</h4>



<p>Now move to 2nd file <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">address.js</mark></code> in which handles user address-related information. Also will see the syntax for named export. To define named export we have to write export preceding to function, variable or class so that can be exported and used in another place. Help of named export we can export multiple function variables and classes.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>// Filename : address.js 
//---------------------------
export let getCity = () =&gt;{
    return &quot;Noida&quot;;
}
export let addressId = 25;</code></pre></div>



<h3 class="wp-block-heading">Importing from a Module in JavaScript ES6</h3>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="579" src="https://www.postnidea.com/wp-content/uploads/2024/11/module-in-javascript-es6-1024x579.png" alt="Importing from a Module in JavaScript ES6" class="wp-image-282" srcset="https://www.postnidea.com/wp-content/uploads/2024/11/module-in-javascript-es6-1024x579.png 1024w, https://www.postnidea.com/wp-content/uploads/2024/11/module-in-javascript-es6-300x170.png 300w, https://www.postnidea.com/wp-content/uploads/2024/11/module-in-javascript-es6-768x434.png 768w, https://www.postnidea.com/wp-content/uploads/2024/11/module-in-javascript-es6.png 1302w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p><strong>Note:</strong><br>For importing modules in html file need to add a type module then the module feature will work and the file call should be from a sever like localhost or any server extensions that are available that can be used like Live server which is compatible with Visual Studio Code if you are using Visual Studio Code.<br><br>So, now we add the main file <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">main.js </mark></code>their code explains further. This file will add the main execution and will use the code that is written in the file <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">user.js</mark></code> and <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">address.js</mark></code>. So, In the HTML file need to add a statement like below</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-html" data-lang="HTML"><code>&lt;script type=&quot;module&quot; src=&quot;main.js&quot; &gt;&lt;/script&gt;</code></pre></div>



<h4 class="wp-block-heading"><strong>Named Imports</strong>:</h4>



<p>you can see below code there is added statement <br><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color"><code>import {getCity, addressId} address from './address.js';</code></mark><br>In which <mark style="background-color:var(--ast-global-color-6)" class="has-inline-color"><code>getCity, addressId</code></mark> are the function and variable and <mark style="background-color:var(--ast-global-color-6)" class="has-inline-color"><code>./address.js</code></mark> path of the file in which function and variable are defined.<br></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>// Filename : main.js 
//---------------------------
import {getCity, addressId} address  from &#39;./address.js&#39;; 
console.log(getCity()); // will print Noida
console.log(addressId); // will print  25</code></pre></div>



<h4 class="wp-block-heading"><strong>Renaming Imports</strong>:</h4>



<p>For code readability or any purpose if need to rename the name of a function, variable, or class name then in the module feature you can do it same thing explored by below code.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>import {addressId as id}  from &#39;./address.js&#39;;
console.log(id) //will print 25</code></pre></div>



<p>Above code, you can see addressId changed as id and print the same.</p>



<h4 class="wp-block-heading"><strong>Import All</strong>:</h4>



<p>In the module import, you can import all function methods and variables in a single variable an object by using using <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">* as</mark></code>  so, that no need to import separately same thing explain by code.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>import * as address  from &#39;./address.js&#39;;
console.log(address.getCity()); // Will print Noida
console.log(address.addressId); // will print id 25</code></pre></div>



<h4 class="wp-block-heading">Default import </h4>



<p>Now let me show how can import the default exported module more and less it works like importing all but there is no need to write <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">* as</mark></code> . </p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>import user  from &#39;./user.js&#39;;
console.log(user.username); // will print Jhon</code></pre></div>



<p>You can also rename in default import.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>import u  from &#39;./user.js&#39;;
console.log(u.username); // will print Jhon</code></pre></div>



<h3 class="wp-block-heading">Benefits of Using Modules</h3>



<ul>
<li><strong>Encapsulation</strong>: Modules make code isolated, you can maintain a global namespace more freely by making block-scoped or module-based code.</li>



<li><strong>Reusability</strong>: The same method and variable can be used anywhere there is no need to define and write code again and again.</li>



<li><strong>Maintainability</strong>: Code becomes more organized and readable so that team members or code reviewers can easily understand the code and easy to maintain future.</li>
</ul>



<h2 class="wp-block-heading">class &amp; object / oops concept in javascript es6</h2>



<p>It is used in approximately all programming languages like PHP, Python, Java, and Javascript. Class-based code has many features like code reusability, readability also helps in memory optimization. It&#8217;s a blueprint for creating objects. This feature of javascript es6 is used by many popular frameworks like React, angular, and nextJs. Class code structure definition and calling are the same in all languages only syntax differences are there. Please check the below example for class.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>class userDetail{
	// Default constructor
	constructor(n){
		this.name = n;
		this.source = &quot;Default&quot;;
	}
	// Individual variable
	user_id = 10;
	// Arrow function
	address = () =&gt; {
		return {city:&quot;Noida&quot;,state:&quot;UP&quot;,country:&quot;India&quot;};
	}
}
let user = new userDetail(&quot;Jhon&quot;); // Set default name by constructor
console.log(user.user_id); // Will print 10
console.log(user.name); // will print Jhon
console.log(user.address().city); // Will print Noida</code></pre></div>



<p>We have defined a constructor which calls when the class is initialized and we can assign variable value. We can do all things in class that we can do in global space like define arrow function and define normal variables.</p>



<h3 class="wp-block-heading">Class Inheritance in javascript es6</h3>



<p>The code that is already defined or written needs to be reused in the context of inheritance. For example in the <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">class userDetail</mark></code> the written method and variable need to be used and write the next code then it&#8217;s possible by Inheritance. The code extended by keyword extends then adds the class name like <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">extends userDetail</mark></code></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>class cart extends userDetail{

	getProducts(){
		return [&quot;Apple Mobile&quot;,&quot;Boat Headphone&quot;,&quot;Mobile Charger&quot;];
	}
}
let user = new cart(&quot;Jhon&quot;); // Set default name by constructor
console.log(user.user_id);   // Will print 10
console.log(user.name); // will print Jhon
console.log(user.getProducts()[0]); // will print Apple Mobile</code></pre></div>



<p>The variable user_id and name is not defined in the class cart but still print name and user_id because the code of existing <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">class  userDetail</mark></code> added or Inherited in <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">class cart</mark></code></p>



<h2 class="wp-block-heading">Array and object Destructuring in in javascript es6</h2>



<p>Assigning values from array or object to a variable or you can say unpack values from an array and assign them to variables.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const colors = [&#39;red&#39;, &#39;green&#39;, &#39;blue&#39;];
const [first, second, third] = colors;

console.log(first);  // Output: &#39;red&#39;
console.log(second); // Output: &#39;green&#39;
console.log(third);  // Output: &#39;blue&#39;</code></pre></div>



<p>In this, if want skip any variable you can do it by skipping assigned variable like below.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const colors = [&#39;red&#39;, &#39;green&#39;, &#39;blue&#39;];
const [first, second] = colors;
console.log(first);  // Output: &#39;red&#39;
console.log(second); // Output: &#39;green&#39;</code></pre></div>



<h4 class="wp-block-heading">Object Destructuring</h4>



<p>You can assign properties to variables by unpacking them from an object utilizing object destructuring. Unless you provide an alternative name, the variable names must correspond to the property names.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const person = { name: &#39;Alice&#39;, age: 25, city: &#39;New York&#39; };
const { name, age, city } = person;
console.log(name); // Output: &#39;Alice&#39;
console.log(age);  // Output: 25

// You can rename variable in object destructuring 

const person = { name: &#39;Alice&#39;, age: 25 };
const { name: personName, age: personAge } = person;
console.log(personName); // Output: &#39;Alice&#39;
console.log(personAge);  // Output: 25</code></pre></div>



<h2 class="wp-block-heading">spread and rest operator in javascript es6</h2>



<p> Both operators are represented by three dots <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">...</mark></code> with the help of these, we can collect the data and spread the next place and also provide flexibility to collect data for function.</p>



<h3 class="wp-block-heading">Spread Operator</h3>



<p>This operator spreads the value of the addition of value to the next variable it works with both array and object. Let&#8217;s understand by code.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>let carBrand = [&quot;Audi&quot;,&quot;Ferrai&quot;,&quot;Hudai&quot;];
let autoBrand = [...carBrand, &quot;Tata&quot;, &quot;Nissan&quot;];
console.log(autoBrand); // will print [ &#39;Audi&#39;, &#39;Ferrai&#39;, &#39;Hudai&#39;, &#39;Tata&#39;, &#39;Nissan&#39; ]

let postAutoBrand = [&quot;Tata&quot;, &quot;Nissan&quot;, ...carBrand];
console.log(postAutoBrand); // will print [ &#39;Tata&#39;, &#39;Nissan&#39;, &#39;Audi&#39;, &#39;Ferrai&#39;, &#39;Hudai&#39; ]</code></pre></div>



<p>In the above code, we have defined three brands in variable <code>carBrand</code>. Now these three values spread in variable autoBrand by using <mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">…</mark> and with the use of spread, you can add values at the start and end of indexing.</p>



<h3 class="wp-block-heading">Rest operator</h3>



<p>It also works the same as the rest operator spread operator works for copy values but the rest operator works for the collection of multiple values or data.<br><strong>Use Case </strong>: <br>Suppose a function needs to pass a dynamic parameter like below.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>function userList(user1, user2, user3){
    return [user1,user2, user3];
}
console.log(userList(&quot;Jhon&quot;, &quot;Ram&quot;, &quot;Nick&quot;)); // [ &#39;Jhon&#39;, &#39;Ram&#39;, &#39;Nick&#39; ]
console.log(userList(&quot;Jhon&quot;)); // [ &#39;Jhon&#39;, undefined, undefined ]</code></pre></div>



<p>You can see that when we did not pass all three parameters in the second call. Then it added undefined on places 2nd and 3rd. So, to fix this issue we have to use the rest operator which collects values in an array format</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>function userList(...users){
    return users;
}
console.log(userList(&quot;Jhon&quot;, &quot;Ram&quot;, &quot;Nick&quot;)); // [ &#39;Jhon&#39;, &#39;Ram&#39;, &#39;Nick&#39; ]
console.log(userList(&quot;Jhon&quot;)); //[ &#39;Jhon&#39; ]</code></pre></div>



<p>Now you can see there is no undefined error the values which you defined will collect it if not then no undefined.</p>



<h4 class="wp-block-heading">Destructuring with Rest Operator</h4>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const fruits = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, &#39;date&#39;];
const [first, second, ...rest] = fruits;

console.log(first);  // Output: &#39;apple&#39;
console.log(second); // Output: &#39;banana&#39;
console.log(rest);   // Output: [&#39;cherry&#39;, &#39;date&#39;]</code></pre></div>



<h2 class="wp-block-heading">Refrence &amp; premitive type variable assigning</h2>



<p>In Primitive type data types (number, string, Symbol, bigint) these are immutable means in this variable the values are directly copied.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>let x = 10;
let y = x; // y is now a copy of x&#39;s value
y = 20;    // changing y does not affect x

console.log(x); // 10
console.log(y); // 20</code></pre></div>



<p>The reference type data type (array &amp; object) not directly values are copied during variable assign there is referencing the pointer that is in memory it will more clearer from the below example.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>let username = { name:&quot;Rakesh Kumar&quot; }
let username2 = username;
console.log(username);// Will print { name: &#39;Rakesh Kumar&#39; }
console.log(username2); // Will print { name: &#39;Rakesh Kumar&#39; }
username2.name=&quot;Jhon&quot;;
console.log(username);// Will print { name: &#39;Jhon&#39; } but expected Rakesh Kumar
console.log(username2); // Will print { name: &#39;Jhon&#39; }</code></pre></div>



<p>In the above example the variable contains the <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">name</mark></code> &#8220;Rakesh Kumar&#8221; Before manipulating the variable <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">username2</mark></code> was print <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">{ name: 'Rakesh Kumar' }</mark></code> but after changing the value in<code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color"> username2.name</mark></code> both are print<code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color"> { name: 'Jhon' }</mark></code> but we changed in <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">username2</mark></code> and username change itself. It happens because both are references to the same location. There is no direct copy of the values.</p>



<p>Now how can we fix this issue so that we can copy the values of one object to another and the original object should be the same or not any modification there? For this, we can use a<strong> spread operator</strong>.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>let username = { name:&quot;Rakesh Kumar&quot; };
let username2 = {...username};
console.log(username);// Will print { name: &#39;Rakesh Kumar&#39; }
console.log(username2); // Will print { name: &#39;Rakesh Kumar&#39; }
username2.name=&quot;Jhon&quot;;
console.log(username);// Will print { name: &#39;Rakesh Kumar&#39; }
console.log(username2); // Will print { name: &#39;Jhon&#39; }</code></pre></div>



<h2 class="wp-block-heading">Array map and array filter in javascript es6</h2>



<h3 class="wp-block-heading">Array Map:</h3>



<p>By giving each element of an existing array a function, the <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">map()</mark></code> method generates a new array. Every element receives a new value from this method, which <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">map()</mark></code> then aggregates into the new array. The original array and its values remain unchanged.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const numbers = [1, 2, 3, 4];
const multiplier = numbers.map(num =&gt; num * 2);
console.log(multiplier); // [2, 4, 6, 8]
console.log(numbers); // [1, 2, 3, 4] (original values unchanged)</code></pre></div>



<h3 class="wp-block-heading">Array filter</h3>



<p>The name filter clearly states that the <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">filter() </mark></code>used for filter the values of the array on the certain business logic or conditions. In this also original array and its values are not changed it creates a new array on the condition <code><mark style="background-color:var(--ast-global-color-6)" class="has-inline-color">true</mark></code>.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-js" data-lang="JavaScript"><code>const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter(num =&gt; num % 2 === 0);
console.log(evenNumbers); // [2, 4]
console.log(numbers);      // [1, 2, 3, 4, 5] (original array remains unchanged)
</code></pre></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p>The complete post is written in keep min in javascript es6. It is a brief discussion about es6 concepts so that you can understand the latest framework and libraries like react, angular, Vue, and react. These front-end technologies are most popular those days but they all use modern javascript concepts. So, I hope you will enjoy the post and try to start learning new frameworks or libraries. Thanks for reading the article.</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/a-refreshing-dive-into-javascript-es6-concepts/">A Refreshing Dive into JavaScript ES6 Concepts</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Start develop chrome extension using javascript in 10 minutes</title>
		<link>https://www.postnidea.com/start-develop-chrome-extension-using-javascript-in-10-minutes/</link>
		
		<dc:creator><![CDATA[Rakesh Kumar]]></dc:creator>
		<pubDate>Mon, 04 Feb 2019 04:37:00 +0000</pubDate>
				<category><![CDATA[chrome extension]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Chrome Extension]]></category>
		<category><![CDATA[Jquery]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>&#8220;It is never too late to learn&#8221;. You know I am late to this experiment. Because people already implemented that. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/start-develop-chrome-extension-using-javascript-in-10-minutes/">Start develop chrome extension using javascript in 10 minutes</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;">
<p style="text-align: justify;">&#8220;It is never too late to learn&#8221;. You know I am late to this experiment. Because people already implemented that. If you have a little bit knowledge of javascript or jquery you can easily create an app for google chrome web store. Web chrome store provides facility to peoples can upload their extensions &amp; publish it publicly. Due to this chrome user have the chance to taste different types of app recipe. One week an ago I was working on an extension at this time I learned about the chrome extension development same thing I share with you.</p>
<h2>File Structure</h2>
<p>Before starting anything let me show you the structure of the extension</p>
<p><img decoding="async" class="alignnone size-full wp-image-154" src="https://www.postnidea.com/wp-content/uploads/2019/02/postnidea-weather-now-file-structure.jpg" alt="" width="235" height="296" /></p>
<p>You can also directly browse my repository by using link <a href="https://github.com/rakeshkumar125/postnidea-weather-now">https://github.com/rakeshkumar125/postnidea-weather-now</a></p>
<h2>Header Information</h2>
<p>Let me first explain the manifest.json file.</p>
<p><script src="https://gist.github.com/rakeshkumar125/9b9381c784091a6cfe751b21d1fcbec3.js"></script></p>
<p>You can see the name, version, description is the fields that contain identification information.</p>
<p style="text-align: justify;">Permission field contains the name of the fields for which you extension need permission to modify or access. Right now I have added only a single one storage but you can allow permission to other fields according to your needs. You can get more information using <a href="https://developer.chrome.com/extensions/declare_permissions" target="_blank" rel="noopener noreferrer">link</a></p>
<p>Icons are the field which contains the set of images which shows for the chrome extension logo on a different resolution.</p>
<p>&#8220;homepage_url&#8221; is the field which contains the publisher or developer website URL so that end user can get the information.</p>
<p>&#8220;browser_action&#8221; field contains the list of resources that will be called when the user performs the action on the browser like click on the chrome extension etc.  In my case, it contains the &#8220;default_popup&#8221; field in which I have defined the name of the file which is called when the user clicks on the chrome extension logo. &#8220;default_icon&#8221; field which contains images for different resolutions.</p>
<p>&#8220;manifest_version&#8221; is the field which contains the version of the manifest file.</p>
<h2>Look &amp; Feel or Client side design</h2>
<p>Now let me start explanation another important file popup.html</p>
<p><script src="https://gist.github.com/rakeshkumar125/557cbee03e2c043a663876323006eb48.js"></script></p>
<p>In above you can see that I have added the HTML part of the extension which is shown when user click on the icon then the user will see the popup content. In the head, I have added two scripts files &#8220;jquery.min.js&#8221; and &#8220;popup.js&#8221;. The &#8220;jquery.min.js&#8221; is the library file which supports for the javascript with the help of that I can user jquery in the extension.</p>
<p>After that, you can see the body part you can see I have added the DIV with id &#8220;weather-report&#8221;. Initially, it has shown with loading image once data fetched from API then it&#8217;s loaded with the report.</p>
<h2>Implement Extension Logic</h2>
<p>Last but not least file &#8220;popup.js&#8221;. You can see the code is below.</p>
<p><script src="https://gist.github.com/rakeshkumar125/f1e51bbb354ad3799601957213c6818d.js"></script></p>
<p>You can see the I first checked that user is connected with the internet or not by using function &#8220;navigator.onLine&#8221;. If the user is online then start preparing the weather report otherwise it will just show the message for connecting to the internet.</p>
<p>If the user connects with internet then I got the current use latitude and longitude of the user by the API (<a href="https://ipv6.ip.nf/me.json" target="_blank" rel="noopener noreferrer">https://ipv6.ip.nf/me.json</a>) which is free. Once I got the user latitude and longitude then Trigger another API (<a href="https://api.openweathermap.org">api.openweathermap.org</a>) for weather report which is also free. After getting weather JSON data then I create HTML using function &#8220;getReportHTML&#8221;.</p>
<p>Finally, load the report to the popup.</p>
<p>You can also check out above explanation using video.</p>
<p>You can also enjoy live demo by clicking on below URL</p>
<p><a href="https://chrome.google.com/webstore/detail/postnidea-weather-now/jiapbdoeogpgpeggldgdhcdalhdchgae" target="_blank" rel="noopener noreferrer">https://chrome.google.com/webstore/detail/postnidea-weather-now/jiapbdoeogpgpeggldgdhcdalhdchgae</a></p>
<p>If you have any query or suggestions you can share by comment.</p>
</div>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/start-develop-chrome-extension-using-javascript-in-10-minutes/">Start develop chrome extension using javascript in 10 minutes</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>angular 6 tutorial for routing and navigation</title>
		<link>https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/</link>
					<comments>https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/#respond</comments>
		
		<dc:creator><![CDATA[Rakesh Kumar]]></dc:creator>
		<pubDate>Wed, 22 Aug 2018 02:07:00 +0000</pubDate>
				<category><![CDATA[angular 6]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angular 7 routing not working]]></category>
		<category><![CDATA[angular cli add routing]]></category>
		<category><![CDATA[angular navigation]]></category>
		<category><![CDATA[angular routing tutorial]]></category>
		<category><![CDATA[how angular routing works]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[router outlet angular 6]]></category>
		<category><![CDATA[Routing]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>Routing a very important part of any application. Routing is a way by which user can navigate your application. Routing [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/">angular 6 tutorial for routing and navigation</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">
<p>Routing a very important part of any application. Routing is a way by which user can navigate your application. Routing is defined by the developer on which route what things need to serve towards client or user. On routing other hidden things also dependent like SEO &amp; feeds. So Bad routing can spoil you application &amp; leave a bad impression on the user. Different technology different way of routing. But front-end user experiences the same.</p>
<p>I have worked on PHP as well as the JS So, I can give the idea about two technologies. For PHP if you using any framework like Codeigniter, CakePHP they already have the option for routing. But If you create PHP application by using class structure then you can use already popular class Altorouter. I have so many options regarding the routing. For more information regarding Altorouter, you can click on the link.</p>
<p>For javascript I working on the angular. The angular has our library with the help of that Angular manage routing. Now today I will show you how angular 5 or angular 6 working. After starting of angular version 2 the angular start using typescript.</p>
<p>Now today I will show you how routing work in the angular 5 or angular 6. So for demonstrating routing in Angular 6, I have to create an application. So with the use of angular CLI tool, you can easily create a new project using the below command.</p>
<h2>Angular generate new application</h2>
<pre><code>ng new {application_name}  or ng new test112</code></pre>
</div>
<p>I create an application for you on your specified path and also install the required packages so that your application will work perfectly.<br />
I will take a few time so, wait with patience. Once your application created then type below command so that your application will open in the browser.</p>
<pre><code>ng serve --open</code></pre>
<p>Above command will compile your typescript and convert in js then compiler compiled thing serve to the browser. There is &#8211;open stand for open browser otherwise. The browser will need to open itself. Now created application working fine.</p>
<h2>Addition of new module in angular application</h2>
<p>Before starting anything few more module I need to install jquery, bootstrap which helps to create awsome UI Design.</p>
<pre><code>npm install bootstrap@3.3.7 jquery --save</code></pre>
<p>After successful installation, we need to add a path in the angular.json file like below which is exist on your application root.</p>
<pre><code>"styles": [
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.js",
              "./node_modules/bootstrap/dist/js/bootstrap.js"
            ]
</code></pre>
<p>There is app.componet.ts already found in the app folder. Now we need to create three pages so that I show perfect routing navigation.<br />
So I will type below commands.</p>
<pre><code>ng generate component home
ng generate component about
ng generate component contact
</code></pre>
<p>Above commands will create three pages for your application. Now one file needs to create app.router.ts which is responsible to complete routing.  In this file, I have to import three ( ModuleWithProviders, Routes, RouterModule)modules which is below.</p>
<pre><code>import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
</code></pre>
<p>I also need to define create page component like below. So that I can include routes variable.</p>
<pre><code>import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { ContactComponent } from './contact/contact.component';
</code></pre>
<h2>Addition of Routing file</h2>
<p>Now I have define a routes array. So that we can store all routes in this variable like below.</p>
<pre><code>export const routes: Routes =[
{path:'home', component: HomeComponent},
{path:'about', component: AboutComponent},
{path:'contact', component: ContactComponent},
];
</code></pre>
<p>export const routing : ModuleWithProviders = RouterModule.forRoot(routes);</p>
<p>Now app.router.ts file is ready finally add to app.module.ts &amp; import module routing using below code.</p>
<pre><code>import { routing } from './app.router';
imports: [
    BrowserModule,
    FormsModule,
    routing]
</code></pre>
<p>Now finally add the navigation to the app.component.html. So the code will look like below.</p>
<p>routerLink=&#8217;home&#8217; will generate the link for the home component &amp; &#8220;routerLinkActive&#8221; will add the active class on the active route.</p>
<p>One more thing needs to add the &lt;router-outlet&gt;&lt;/router-outlet&gt; so that all component will show their data in it.</p>
<p>Finally, you can view the output.</p>
<h2>Above code works in below video</h2>
<p><iframe src="https://www.youtube.com/embed/ljkhCvNwJQ4" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
<p><a class="btn btn-primary btn-blue" href="http://demo.postnidea.com/test112/" target="_blank" rel="noopener noreferrer">Demo</a> <a class="btn btn-primary btn-blue" href="https://github.com/postnidea/angular-6-tutorial-for-routing-and-navigation" target="_blank" rel="noopener noreferrer">code</a></p>
</div>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/">angular 6 tutorial for routing and navigation</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.postnidea.com/angular-6-tutorial-for-routing-and-navigation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
