<?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>JavaScrip Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/javascrip/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/javascrip/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Wed, 12 May 2021 15:28:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>JavaScript Cheat Sheet — JSON, Loops, and Promises</title>
		<link>https://www.scmgalaxy.com/tutorials/javascript-cheat-sheet%e2%80%8a-%e2%80%8ajson-loops-and-promises/</link>
					<comments>https://www.scmgalaxy.com/tutorials/javascript-cheat-sheet%e2%80%8a-%e2%80%8ajson-loops-and-promises/#respond</comments>
		
		<dc:creator><![CDATA[dharmendra K]]></dc:creator>
		<pubDate>Wed, 12 May 2021 15:20:55 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[JavaScrip]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[Promises]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/?p=6226</guid>

					<description><![CDATA[<p>JavaScript is one of the most popular programming languages for web programming. In this article, we’ll look at the basic [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/javascript-cheat-sheet%e2%80%8a-%e2%80%8ajson-loops-and-promises/">JavaScript Cheat Sheet — JSON, Loops, and Promises</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">JavaScript is one of the most popular programming languages for web programming.</p>



<p class="wp-block-paragraph">In this article, we’ll look at the basic syntax of modern JavaScript</p>



<h3 class="wp-block-heading">JSON</h3>



<p class="wp-block-paragraph">We can create JSON strings from JavaScript objects with the <code>JSON.stringify</code> method:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="323" height="134" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-3.jpg" alt="" class="wp-image-6231" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-3.jpg 323w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-3-300x124.jpg 300w" sizes="(max-width: 323px) 100vw, 323px" /></figure>



<p class="wp-block-paragraph">And we can convert JSON strings back to JavaScript objects with <strong><code>JSON.parse</code> :</strong></p>



const obj = JSON.parse(json);



<p class="wp-block-paragraph">We can use it to store data in local storage.</p>



<p class="wp-block-paragraph">We’ve to convert objects into strings first to store them.</p>



<p class="wp-block-paragraph">To store objects we call <strong><code>localStorage.setItem</code> :</strong></p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="365" height="158" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-4.jpg" alt="" class="wp-image-6232" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-4.jpg 365w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-4-300x130.jpg 300w" sizes="(max-width: 365px) 100vw, 365px" /></figure>



<p class="wp-block-paragraph">The first argument is the key.</p>



<p class="wp-block-paragraph">And we can get data by their keys with <strong><code>getItem</code> :</strong></p>



localStorage.getItem(&#8216;json&#8217;)



<h3 class="wp-block-heading">Loops</h3>



<p class="wp-block-paragraph">avaScript comes with various kinds of loops.</p>



<p class="wp-block-paragraph">One kind of loop is the <strong><code>for</code> </strong>loop<strong>:</strong></p>



for (let i = 0; i < 10; i++) {
  console.log(i);
}



<p class="wp-block-paragraph">We can loop through any kind of iterable object with the <code><strong>for-of</strong></code> loop:</p>



for (let i of custOrder) {
  console.log(i);
}



<p class="wp-block-paragraph">Some iterable objects include arrays, strings, and node lists.</p>



<p class="wp-block-paragraph">Another kind of loop is the <code><strong>while</strong></code> loop:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="244" height="121" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-5.jpg" alt="" class="wp-image-6233"/></figure>



<p class="wp-block-paragraph">There’s also the <code><strong>do-while</strong></code> loop:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="281" height="135" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-6.jpg" alt="" class="wp-image-6234"/></figure>



<p class="wp-block-paragraph">The <code><strong>break</strong></code> keyword lets us end the loop early:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="340" height="148" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-7.jpg" alt="" class="wp-image-6235" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-7.jpg 340w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-7-300x131.jpg 300w" sizes="auto, (max-width: 340px) 100vw, 340px" /></figure>



<p class="wp-block-paragraph">The <strong><code>continue</code> </strong>keyword lets us skip to the next iteration:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="360" height="144" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-8.jpg" alt="" class="wp-image-6236" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-8.jpg 360w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-8-300x120.jpg 300w" sizes="auto, (max-width: 360px) 100vw, 360px" /></figure>



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



<p class="wp-block-paragraph">JavaScript comes with various data types.</p>



<p class="wp-block-paragraph">They include:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="538" height="184" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-10.jpg" alt="" class="wp-image-6239" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-10.jpg 538w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-10-300x103.jpg 300w" sizes="auto, (max-width: 538px) 100vw, 538px" /></figure>



<h3 class="wp-block-heading">Objects</h3>



<p class="wp-block-paragraph">We can create an object with curly braces:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="461" height="179" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-11.jpg" alt="" class="wp-image-6240" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-11.jpg 461w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-11-300x116.jpg 300w" sizes="auto, (max-width: 461px) 100vw, 461px" /></figure>



<p class="wp-block-paragraph">It has properties and methods.</p>



<p class="wp-block-paragraph"><strong><code>this</code> </strong>is the <code><strong>student</strong></code> object itself.</p>



<p class="wp-block-paragraph">We can call <code><strong>fullName</strong></code> with <strong><code>student.fullName()</code> .</strong></p>



<p class="wp-block-paragraph">And we can assign values to properties with:</p>



student.age = 19;



<h3 class="wp-block-heading">Promises</h3>



<p class="wp-block-paragraph">We can create promises with the <code><strong>Promise</strong></code> constructor:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="605" height="212" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-12.jpg" alt="" class="wp-image-6241" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-12.jpg 605w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-12-300x105.jpg 300w" sizes="auto, (max-width: 605px) 100vw, 605px" /></figure>



<p class="wp-block-paragraph">We can <strong><code>resolve</code> </strong>to fulfill the promise with the sum.</p>



<p class="wp-block-paragraph">And we call <code><strong>reject</strong></code> to reject the promise with an error.</p>



<p class="wp-block-paragraph">Then we can call <code><strong>then</strong></code> to get the resolved value and <code><strong>catch</strong></code> to get the error values:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="286" height="149" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/05/25-13.jpg" alt="" class="wp-image-6242"/></figure>



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



<p class="wp-block-paragraph">We can work with JSON, local storage, promises, and loops with JavaScript.</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/javascript-cheat-sheet%e2%80%8a-%e2%80%8ajson-loops-and-promises/">JavaScript Cheat Sheet — JSON, Loops, and Promises</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/javascript-cheat-sheet%e2%80%8a-%e2%80%8ajson-loops-and-promises/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
