<?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>jQuery Archives - Postnidea</title>
	<atom:link href="https://www.postnidea.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.postnidea.com/category/jquery/</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>jQuery Archives - Postnidea</title>
	<link>https://www.postnidea.com/category/jquery/</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>wordpress posts validation using ajax in backend</title>
		<link>https://www.postnidea.com/wordpress-posts-validation-using-ajax-in-backend/</link>
					<comments>https://www.postnidea.com/wordpress-posts-validation-using-ajax-in-backend/#respond</comments>
		
		<dc:creator><![CDATA[Rakesh Kumar]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 02:57:00 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress contextual help]]></category>
		<category><![CDATA[wordpress plugin]]></category>
		<category><![CDATA[ajax validation]]></category>
		<category><![CDATA[post ajax validation]]></category>
		<category><![CDATA[wordpess post validation]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>In WordPress already so many hooks &#38; filter available with the help of that you can customize the wordpress according [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/wordpress-posts-validation-using-ajax-in-backend/">wordpress posts validation using ajax in backend</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>In WordPress already so many hooks &amp; filter available with the help of that you can customize the wordpress according to our needs. But there are some customizations that are required more tricky solutions. For handling ajax request WordPress already define our rules &amp; standards but sometimes there is a need to performing ajax request on the default page saving. For the javascript WordPress uses js enqueue<br />
function with the help of you can attach javascript files &amp; functions. For creating ajax request action WordPress uses two below functions</p>
<p>When you calling the actions publically the use the below functions. There is no need requirement of the login.<br />
admin_post_nopriv_{action_name}<br />
If you want action to execute only when the user login.<br />
admin_post_{action_name}</p>
<p>If you want to call an action on login or without login then use both functions. Now I show you how to call the action in our Ajax request.<br />
http://your_host/admin-ajax.php<br />
On above URL you can pass the action: name using a post or get request then execution of the action occurs. But some problem comes due to customization then there is a need a tricky solution. You can see the below problem.</p>
<p>Problem:</p>
<p>We need to add some extra fields (custom fields) on WordPress backend page. When a user clicks on &#8220;publish&#8221; button then we call the API &amp; values fill with the response from the API then we submit WordPress page form. We implemented all but page always goes to Draft.</p>
<p>Solution:<br />
In a below code post status select box I have check if there is user select &#8220;Draft&#8221; I set the draft otherwise we put the status the publish so that we have to fix that problem. The above-explained things done by function &#8220;check_status&#8221;.</p>
<pre><code>
$("#publish:button").click(function(){
	$.get("url").done(function(data){
		if(check_status()){} else{
		$("#acf-field-region").after("");
		}

		$(document).find("#publish").prop("type", "submit");
		setTimeout(function(){

		$("#post").submit();

		},100);

		return false;
	})
	event.preventDefault();
});
</code></pre>
<pre><code>
function check_status(){
	var status=0;
	jQuery("#post_status option").each(function(){
		if(jQuery(this).val()=="publish"){
			status=1;
		}
	});
	return status;
}
</code></pre>
</div>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/wordpress-posts-validation-using-ajax-in-backend/">wordpress posts validation using ajax in backend</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.postnidea.com/wordpress-posts-validation-using-ajax-in-backend/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>jquery form validation using php with mysql database</title>
		<link>https://www.postnidea.com/jquery-form-validation-using-php-with-mysql-database/</link>
					<comments>https://www.postnidea.com/jquery-form-validation-using-php-with-mysql-database/#respond</comments>
		
		<dc:creator><![CDATA[Rakesh Kumar]]></dc:creator>
		<pubDate>Mon, 16 Jan 2017 17:45:00 +0000</pubDate>
				<category><![CDATA[dynamic form validation]]></category>
		<category><![CDATA[form validation]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[validation library]]></category>
		<category><![CDATA[Form validation]]></category>
		<category><![CDATA[Jquery form validation]]></category>
		<category><![CDATA[mysql database validation]]></category>
		<category><![CDATA[php server side validation]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[<p>Nowadays jquery or Javascript is more prominent. Every client wants their application to become faster &#38; user interactive so they [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/jquery-form-validation-using-php-with-mysql-database/">jquery form validation using php with mysql database</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;">Nowadays jquery or Javascript is more prominent. Every client wants their application to become faster &amp; user interactive so they good user experience, get more customer. Whenever you complete our functionality with ajax request that makes attractiveness because user stays on the same page he sees there task also complete only dom element manipulation occurring. So I figure one common functionality required everywhere which form validation. Without form validation, you can not be complete our functionality of our requirement.</p>
<p style="text-align: justify;">A few days ago I was written a PHP class that deal with validation you can review by click on that link <a title="PHP class for form validation" href="http://postnidea.com/php-class-form-validation/">Click</a>. So in this validation, i write methods of different validation like blank, number, email, validation of field from database like a username. When you review code <a title="PHP class for form validation" href="http://postnidea.com/php-class-form-validation/">Click</a> you will find there is no ajax no form code only a PHP class which shows validation. So require a javascript class that can use for process our request.</p>
<h2>Implementation of jquery form validation using php with mysql database</h2>
<p style="text-align: justify;">Now we start to create a javascript class for processing form. For my javascript code, i have dependency with bootstrap which common CSS framework, with the usage of that framework you can complete our application with responsive design without any help of a designer.<br />
I write a small chunk of code a form which is below.</p>
<p><script src="https://gist.github.com/postnidea/5d8d29110513ca37bb2a604ec03ee4fa.js"></script></p>
<p style="text-align: justify;">In above code, form tag has two selectors like id, action both are required for the form processing. Action are required on which you form being processed. ID is required for pick values suppose if multiple forms then it will more helpful. Another is &#8220;Submit&#8221; button with their click event we fire a request &amp; process it. After processing it will return JSON format response on the basis of that we can manipulate the DOM elements. So we require a function when we click on the submit button it will perform required function. Now below I write a code.</p>
<p><script src="https://gist.github.com/postnidea/2ace7272561b0d54ddad8f4f732d4d3c.js"></script></p>
<p style="text-align: justify;">In above code &#8220;server_validation&#8221; its function for which need to pass the certain parameter on the basis of that it perform form processing. The parameter explanation is below</p>
<p>form_id:&#8217;add_form&#8217; // its the Id of form<br />
button_id:&#8217;add_button&#8217;, // its the Id button<br />
after_success:load_success // its the name of function that call after success of form.</p>
<p>With the help of above code you can just validate form but if you want any callback function then call below function</p>
<p><script src="https://gist.github.com/postnidea/56a36d3d831215a889015dc28a332055.js"></script></p>
<p style="text-align: justify;">In the above code, every thing is same only I added the &#8220;after_success&#8221; variable in which I pass the name of the function that needs to call after the success of form.</p>
<p><a class="btn btn-primary btn-blue" href="http://demo.postnidea.com/jquery-form-validation-using-php/" target="_blank" rel="noopener noreferrer">Demo</a> <a class="btn btn-primary btn-blue" href="https://github.com/postnidea/jquery-form-validation-using-php" target="_blank" rel="noopener noreferrer">code</a></p>
</div>
<p>The post <a rel="nofollow" href="https://www.postnidea.com/jquery-form-validation-using-php-with-mysql-database/">jquery form validation using php with mysql database</a> appeared first on <a rel="nofollow" href="https://www.postnidea.com">Postnidea</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.postnidea.com/jquery-form-validation-using-php-with-mysql-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
