<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ganesh Jaiwal</title>
    <description>The latest articles on DEV Community by Ganesh Jaiwal (@ganeshjaiwal).</description>
    <link>https://dev.to/ganeshjaiwal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F462671%2F67f6eaf1-e1af-48dd-b13f-77a20e4412dd.png</url>
      <title>DEV Community: Ganesh Jaiwal</title>
      <link>https://dev.to/ganeshjaiwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ganeshjaiwal"/>
    <language>en</language>
    <item>
      <title>JavaScript Strings</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Thu, 12 Nov 2020 14:26:11 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/javascript-strings-a00</link>
      <guid>https://dev.to/ganeshjaiwal/javascript-strings-a00</guid>
      <description>&lt;p&gt;Every programming language has a set of data types that they support.&lt;br&gt;
JavaScript also has datatypes that I explained in  &lt;a href="https://dev.to/ganeshjaiwal/types-values-and-variables-in-javascript-pka"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The most used data types are Numbers and Strings/text.&lt;/p&gt;

&lt;p&gt;I already covered Numbers in detail in the  &lt;a href="https://dev.to/ganeshjaiwal/numbers-in-javascript-50no"&gt;previous article&lt;/a&gt; .&lt;br&gt;&lt;br&gt;
In this article, we will see strings/text datatype of JavaScript in detail.&lt;/p&gt;

&lt;p&gt;So what if you want to store your name in some variable, it will be hard to store each character in a separate variable or storing all character in an array.&lt;/p&gt;

&lt;p&gt;C language uses an array of characters to represent a string.&lt;/p&gt;

&lt;p&gt;JavaScript provides a separate Data type to represent a sequence of characters i.e. &lt;strong&gt;String&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a string in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The string is an immutable sequence of 16-bit values, each of which represents a Unicode character.&lt;/p&gt;

&lt;p&gt;JavaScript’s strings(and it’s array) use zero-based indexing.&lt;br&gt;
The first 16-bit value is represented at position 0, the second 16-bits at position 1, and so on.&lt;/p&gt;
&lt;h3&gt;
  
  
  So what is the length of the string then?
&lt;/h3&gt;

&lt;p&gt;JavaScript string length is calculated as the number of 16-bit values it contains.&lt;/p&gt;
&lt;h4&gt;
  
  
  Note:-
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;JavaScript doesn’t have a specific data type to represent a single 16-bit value.&lt;br&gt;
It will be represented as a string of length 1.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Javascript uses the UTF-16 encoding of the Unicode character set.&lt;br&gt;
The most commonly used Unicode characters are fit into 16-bit and can be represented by a single element.&lt;br&gt;&lt;br&gt;&lt;br&gt;
Unicode characters that don’t fit into 16-bit are encoded using rules of UTF-16 as a sequence(known as “Surrogate pair”) of two 16-bit values. This means JavaScript string with a single character may return length as 2.&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;:- &lt;br&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let dollar = “$”;
let emoji = “🤘”;
dollar.length;       // 1
emoji.length;       // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In ES6 if we iterate string with for loop it considers 2 16-bit values as a single character if it is “Surrogate pair”.&lt;/p&gt;

&lt;h3&gt;
  
  
  String Literals
&lt;/h3&gt;

&lt;p&gt;To use strings directly into the JavaScript program, simply enclose the characters of the string within a matched pair of single/double-quotes.&lt;br&gt;
In ES6 JavaScript provided backticks(`) to represent a string in a simpler way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;:- &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
‘Hello Devs’&lt;br&gt;
“I’m Ganesh.”&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The original version of JavaScript required string literals to be written on a single line. And to create a long string it is common to concatenating string using the + operator.&lt;/p&gt;

&lt;p&gt;As of ES5, you can break the string into multiple lines by adding a backslash() at the end of the line.&lt;br&gt;&lt;br&gt;
The ES6 made it easier for devs to write a string into multiple lines with backticks, without adding any special characters like(\n).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;“Long \&lt;br&gt;
string \&lt;br&gt;
With ES5”&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Escape Sequence in String Literals
&lt;/h3&gt;

&lt;p&gt;The backslash character () has a special purpose in Javascript strings. Combined &lt;br&gt;
with the character that follows it, it represents a character that is not otherwise representable within the string.&lt;/p&gt;

&lt;p&gt;The backslash () allows you to escape from the usual interpretation of the single-quotes character. Instead of using it as the end of the string, you use it as a single quote.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
‘Hello, dev\’s you\’re Awesome.’       // =&amp;gt; Hello, dev’s you’re Awesome.&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;A table that represents JavaScript escape sequence.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ii7RbcCt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1605017988208/aARGRRVJq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ii7RbcCt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1605017988208/aARGRRVJq.png" alt="JavaScriptEscape sequence.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Working with string
&lt;/h3&gt;

&lt;p&gt;If we use the + operator with numbers it adds them, but using the + operator on string results in concatenating 2 strings.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
let text = “Hello ” + “world!!!!”;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A string can be compared with ===(equality) or !==(inequality) operators, two strings are equal if they consist of exactly the same sequence of 16-bit values.&lt;/p&gt;

&lt;p&gt;A string can also be compared with the &amp;lt;, &amp;lt;=, &amp;gt;, and &amp;gt;= operators.&lt;br&gt;&lt;br&gt;
String comparison is done simply by comparing the 16-bit values.&lt;/p&gt;

&lt;p&gt;As I mentioned before the length of a string is the number of 16-bit values it contains.&lt;/p&gt;

&lt;p&gt;JavaScript provides a rich API for working with string.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
let str = "Hello, JavaScript Lovers.";&lt;/p&gt;

&lt;p&gt;// Getting portion of the string&lt;br&gt;
str.substring(1, 8);    // "ello, J"    charates from 1 to 8&lt;br&gt;
str.slice(1, 8);        // "ello, J"    charates from 1 to 8&lt;br&gt;
str.slice(-4);        // "ers."    last 4 characters&lt;br&gt;
str.split(',');      // ["Hello", " JavaScript Lovers."]&lt;/p&gt;

&lt;p&gt;// Searching a string&lt;br&gt;
str.indexOf('J');       // 7        Position of first “J”&lt;br&gt;
str.indexOf('44');     // -1       “44” not present in str&lt;br&gt;
str.lastIndexOf('l');   // 3        Position of “l” from last&lt;/p&gt;

&lt;p&gt;// Searching function of ES6 and later&lt;br&gt;
str.startsWith('He');   // true     Checks if string starts with “He”&lt;br&gt;
str.endsWith('He');   // false      Checks if string ends with “He”&lt;br&gt;
str.includes('JavaScript'); // true     Checks if string contains “JavaScript”&lt;/p&gt;

&lt;p&gt;// Modifying string &lt;br&gt;
str.replace('JavaScript', 'tea'); //  "Hello, tea Lovers."  Replaces the maching part of string&lt;br&gt;
str.toLowerCase();  // "hello, javascript lovers."  Converts string to lower case&lt;br&gt;
str.toUpperCase();  // "HELLO, JAVASCRIPT LOVERS."  Converts string to upper case&lt;/p&gt;

&lt;p&gt;// Inspecting individual 16-bit characters of string&lt;br&gt;
str.charAt(0);      // “H”      Returns character at position 0&lt;br&gt;
str.charAt(str.length - 2); // “s”   Getting 2nd last character of string&lt;br&gt;
str.charCodeAt(0);  // 72   16-bit number at position 0&lt;br&gt;
str.codePointAt(0); // 72   ES6 - this world for codepoints &amp;gt; 16-bits&lt;/p&gt;

&lt;p&gt;// String padding functions in ES2017&lt;br&gt;
"xyz".padStart(6);  // "    xyz"    add spaces on the left of string and make length 6&lt;br&gt;
"xyz".padEnd(6);    // "xyz    "    add spaces on the righ of string and make length 6&lt;br&gt;
"xyz".padStart(6, "#");     // "###xyz" add # as padding&lt;br&gt;
"xyz".padEnd(6, "#");   // "xyz###" add # as padding&lt;/p&gt;

&lt;p&gt;// Space trimming functions trim() of ES5 and others from ES2019&lt;br&gt;
"   xyz   ".trim(); // "xyz"    Removes empty spaces from start and end&lt;br&gt;
"   xyz   ".trimStart();    // "xyz   "     Removes empty spaces from start&lt;br&gt;
"   xyz   ".trimEnd();  // "   xyz"     Removes empty spaces from end&lt;/p&gt;

&lt;p&gt;// More string methods&lt;br&gt;
str.concat("!!");       // "Hello, JavaScript Lovers.!!"   Same as + operator&lt;br&gt;
"=".repeat(5);      // "====="  Repetes characters n times&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  NOTE:-
&lt;/h4&gt;

&lt;p&gt;JavaScript Strings are immutable. Methods like replace() or toUpperCase() returns new string with resulting value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Template Literals
&lt;/h3&gt;

&lt;p&gt;In Es6 and later, strings are represented using backticks.&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
let str =&lt;/code&gt;Hello there.&lt;code&gt;;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt; &lt;br&gt;
This is more than just another string literal syntax.&lt;br&gt;&lt;br&gt;
Template literals can include arbitrary javascript expression. The final value of string literal in backtick is computed by evaluating any included expression, converting the values of those expressions to a string.&lt;/p&gt;

&lt;p&gt;Example:-&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
&lt;/code&gt;Addition of 2 + 4 is ${2 + 4}.&lt;code&gt;// "Addition of 2 + 4 is 6."&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;That’s it for the strings in JavaScript.&lt;br&gt;&lt;br&gt;
I hope you liked this article.&lt;br&gt;&lt;br&gt;
In the next article of this series, I will be covering Expressions and operators part-1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ganeshjaiwal/numbers-in-javascript-50no"&gt;← Numbers in JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Numbers in JavaScript</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Wed, 04 Nov 2020 11:06:01 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/numbers-in-javascript-50no</link>
      <guid>https://dev.to/ganeshjaiwal/numbers-in-javascript-50no</guid>
      <description>&lt;p&gt;To represent numeric value in javascript we need to use numbers.&lt;br&gt;&lt;br&gt;
As I mentioned in my previous article(&lt;a href="https://dev.to/ganeshjaiwal/types-values-and-variables-in-javascript-pka"&gt;Types Values and variables in Javascript&lt;/a&gt;) we need to use specific data types to store specific values.&lt;/p&gt;

&lt;p&gt;In our case, if we want to store some numeric value we need to use a &lt;strong&gt;number data type&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript represents numbers using the 64-bit floating-point format defined by the IEEE 754 standard.&lt;/p&gt;

&lt;p&gt;The JavaScript number format allows us to represent all numeric values between, &lt;strong&gt;-9,007,199,254,740,992 (-2⁵³)&lt;/strong&gt; and &lt;strong&gt;9,007,199,254,740,992 (2⁵³)&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
If we use values larger than this we may lose precision in trailing digits.&lt;/p&gt;

&lt;p&gt;If a number appears directly in a JavaScript program, it called numeric literals.&lt;br&gt;&lt;br&gt;
JavaScript supports numeric literals in several formats.&lt;br&gt;&lt;br&gt;
Let’s look into it one by one.&lt;/p&gt;
&lt;h3&gt;
  
  
  Integer Literals
&lt;/h3&gt;

&lt;p&gt;In the JavaScript program, we can use the sequence on digits from 0 to 9, to represent any base-10 numeric values.&lt;/p&gt;

&lt;p&gt;Examples:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
88
56
555986547
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript also allows us to use hexadecimal values(base-16). Hexadecimal literals are represented by adding &lt;strong&gt;0x or 0X&lt;/strong&gt; as a prefix to that number.&lt;br&gt;&lt;br&gt;
It uses &lt;strong&gt;0 to 9 or a(or A) to f(or F)&lt;/strong&gt; witch represents values from 10 to 15.&lt;/p&gt;

&lt;p&gt;Examples:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0xfca99       // =&amp;gt; 1034905 = (15 × 16⁴) + (12 × 16³) + (10 × 16²) + (9 × 16¹) + (9 × 16⁰)
8873          // =&amp;gt; 34931 = (8 × 16³) + (8 × 16²) + (7 × 16¹) + (3 × 16⁰)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In ES6 and later, we can also represent integers in binary(base-2) or octal(base-8) using prefixes &lt;strong&gt;0b and 0o(or 0B and 0O)&lt;/strong&gt; respectively.&lt;/p&gt;

&lt;p&gt;Examples:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0b110110110        // =&amp;gt; (1 × 2⁸) + (1 × 2⁷) + (0 × 2⁶) + (1 × 2⁵) + (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰)
0o57246            // =&amp;gt; (5 × 8⁴) + (7 × 8³) + (2 × 8²) + (4 × 8¹) + (6 × 8⁰)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Floating Point literals
&lt;/h3&gt;

&lt;p&gt;Floating-point literals can have decimal point.&lt;br&gt;&lt;br&gt;
A real value is represented as an integral part of the number, followed by a decimal point and fractional part of the number.&lt;/p&gt;

&lt;p&gt;Floating-point literals can also be represented using exponential notation.&lt;br&gt;&lt;br&gt;
A real number followed by letter &lt;strong&gt;e(or E)&lt;/strong&gt; with optional +/- sign, followed by an integer exponent.&lt;/p&gt;

&lt;p&gt;This notation represents a real number multiplied by 10 to the power of the exponent.&lt;/p&gt;

&lt;p&gt;Examples:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.14
55482.2287
7.9985e33     // =&amp;gt; 7.9985 × 10²³
1.221533E-11  // =&amp;gt; 1.221533 × 10⁻¹¹
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We can use separators in numeric literals to make them easier to read.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let no1 = 1_000_222_444;
let no2 = 2.111_125_255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the moment, using an underscore in numeric literals is not formally standardized yet. But they are in the advanced stage of the standardization process and implemented by major browsers and Node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arithmetic in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript program works with numbers using arithmetic operators, that language provides.&lt;br&gt;&lt;br&gt;
These includes &lt;strong&gt;+, -, *, /, and %.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;%(Modulo)&lt;/strong&gt; is used to get a &lt;strong&gt;remainder after division&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;ES2016 adds ** for exponentiation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:-&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20**4 // =&amp;gt; 160000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arithmetic in JavaScript does not raise an error in case of overflow, underflow, or division by zero.&lt;br&gt;&lt;br&gt;
When the number(or a result of the operation) is larger than the largest representable number(overflow), the resulting value is a special infinite value, &lt;strong&gt;Infinity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, if the number(or a result of the operation) is smaller than the smallest representable value, the resulting special value is negative infinity, &lt;strong&gt;-Infinity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The zero divide by zero does not have a well-defined value and the result of this operation is a special not-a-number value(&lt;strong&gt;NaN&lt;/strong&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Date and Time
&lt;/h3&gt;

&lt;p&gt;JavaScript defined simple Date class for representing and manipulating numbers that represent date and time.&lt;br&gt;&lt;br&gt;
JavaScript Dates are objects but they also have numeric representations as timestamp, which specifies the number of elapsed milliseconds since 1st January 1970.&lt;/p&gt;

&lt;p&gt;That’s all I wanted to cover about Numbers data type in JavaScript.&lt;br&gt;
In an upcoming article in this series, I will cover the &lt;strong&gt;Text data type of JavaScript&lt;/strong&gt; in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.ganeshjaiwal.dev/types-values-and-variables-in-javascript"&gt;← Types, values, and variables in JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Types, values, and variables in JavaScript</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Wed, 28 Oct 2020 15:51:03 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/types-values-and-variables-in-javascript-pka</link>
      <guid>https://dev.to/ganeshjaiwal/types-values-and-variables-in-javascript-pka</guid>
      <description>&lt;p&gt;In this article, we will take an overview of types, values, and variables in JavaScript.&lt;/p&gt;

&lt;p&gt;A compuer program can simply be explained as a piece of code that manipulates something.&lt;/p&gt;

&lt;p&gt;So what is something?&lt;/p&gt;

&lt;p&gt;Let’s ask the computer to perform some task,&lt;br&gt;
&lt;em&gt;Hey, computer print “Hello Devs” 2 times.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, in the above statement, there are two &lt;strong&gt;entities&lt;/strong&gt;,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;“Hello Devs”&lt;/li&gt;
&lt;li&gt;2&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These will be the &lt;strong&gt;values&lt;/strong&gt; used by the computer program.&lt;br&gt;
First is a set of characters and the second is digit/number these are called &lt;strong&gt;types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ok, what if we want these values later in our program?&lt;br&gt;
Let’s save values in some container and name that container as &lt;strong&gt;abc&lt;/strong&gt;.&lt;br&gt;
This container is called a &lt;strong&gt;variable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript types mainly can be divided into two categories:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Primitive types&lt;/li&gt;
&lt;li&gt;Object type&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Primitive types include &lt;strong&gt;numbers, strings of text,&lt;/strong&gt; and &lt;strong&gt;boolean&lt;/strong&gt; values(true/false).&lt;br&gt;
The special type of values like null and undefined are primitive values, but they are not numbers, strings, or boolean.&lt;br&gt;
ES6 added a new special-purpose type, known as &lt;strong&gt;Symbol&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Any value that is not a primitive value(number, string, boolean, symbol, null, or undefined) is an &lt;strong&gt;Object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An object is a collection of properties where each property has a name and value pair.&lt;br&gt;
The values of an object can be a primitive value or another object.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript automatically converts values from one type to another. If the program expects a string and you provided a number, it will automatically convert the number to a string.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;p&gt;The number is used to represent integers.&lt;br&gt;
JavaScript represents numbers using a 64-bit floating-point format defined by IEEE 754 standard.&lt;/p&gt;

&lt;p&gt;This means it can represent numbers as large as +/- 1.7976931348623157*10^308 and as small as +/- 5*10^-324.&lt;/p&gt;

&lt;p&gt;If we use integer values larger than the range, we may lose precision in trailing digits.&lt;/p&gt;

&lt;p&gt;If a number appears directly in a JavaScript program it is called &lt;strong&gt;numeric literals&lt;/strong&gt;.&lt;br&gt;
I will explain Numbers in detail in an upcoming article.&lt;/p&gt;
&lt;h2&gt;
  
  
  Text
&lt;/h2&gt;

&lt;p&gt;To represent text in our program JavaScript provides type as a String.&lt;br&gt;&lt;br&gt;
A String is an immutable ordered sequence of 16-bit values. Each 16-bit value represents a Unicode character.&lt;br&gt;&lt;br&gt;
The length is the number of 16-bit values that are used to represent a string.&lt;br&gt;
JavaScript strings use zero-based indexing, the first 16-bit value is placed at 0th index and 2nd at 1st index, and so on.&lt;/p&gt;

&lt;p&gt;You can find details about strings in javascript in upcoming articles.&lt;/p&gt;
&lt;h2&gt;
  
  
  Boolean values
&lt;/h2&gt;

&lt;p&gt;null is a reserved keyword to represent the absence of the value.&lt;br&gt;&lt;br&gt;
Using typeof operator on null returns type as an “object”, indicating that null can be used as a special value that indicates “no object”.&lt;br&gt;&lt;br&gt;
Other programming languages also have equivalent Javascript null: like NULL, nil, or None.&lt;/p&gt;

&lt;p&gt;The undefined value represents a deeper kind of absence. It is the value of the variable that not has been initialized.&lt;br&gt;&lt;br&gt;
Many times we see this value when we try to get the value of an object property or array element which does not exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;undefined is a predefined global constant(not language keyword as null) that is initialized to an undefined value.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we try to apply typeof operator to an undefined value it returns “undefined”, indicating that this is a member of a special type.&lt;/p&gt;
&lt;h2&gt;
  
  
  Symbols
&lt;/h2&gt;

&lt;p&gt;Symbols were introduced in ES6 to use non-string property names.&lt;br&gt;&lt;br&gt;
JavaScript Object types are an unordered collection of properties, where each property has a name and value.&lt;br&gt;&lt;br&gt;
Before ES6 property names are typically a &lt;strong&gt;string&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To obtain symbol values, we need to call the Symbol() function.&lt;br&gt;
This function never returns the same value twice even we call it with the same argument.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Symbol.for()-&lt;/strong&gt;&lt;br&gt;
This method allows us to create the same symbol value twice.&lt;br&gt;
Passing the same string argument to Symbol.for() method returns the same symbol value.&lt;br&gt;
&lt;strong&gt;Symbol.keyFor()&lt;/strong&gt; returns the string that we passed as an argument to &lt;strong&gt;Symbol.for()&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let var1 = Symbol.for(“test”);
let var2 = Symbol.for(“test”);
va1 === var2              // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Variable Declaration and Assignment
&lt;/h2&gt;

&lt;p&gt;In the programming language, we use names/identifiers to represent values.&lt;br&gt;&lt;br&gt;
Binding name to value gives us a way to refer to that value ad use it in the programs we write.&lt;br&gt;&lt;br&gt;
By doing this we can say that we are assigning value to a variable.&lt;/p&gt;

&lt;p&gt;The term variable implies that a new value can be assigned: the value associated with the variable may vary as our program runs.&lt;br&gt;&lt;br&gt;
If we permanently assign some value to a name, that name we refer to as constant instead of variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Variable and scope
&lt;/h3&gt;

&lt;p&gt;The scope of a variable is the region of our program source code in which it is defined.&lt;br&gt;&lt;br&gt;
Variable and constant declared with let and const are blocked scope. This means the variable is only accessible inside the code block where let or const exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  var as a global variable
&lt;/h3&gt;

&lt;p&gt;If we declare the global variable using the var keyword it is a part of the global object and can be referred to as globalThis.&lt;br&gt;&lt;br&gt;
Global declared with var can not be deleted using the delete keyword.&lt;br&gt;&lt;br&gt;
Variable declared with let and const are not a part of globalThis.&lt;/p&gt;

&lt;p&gt;This is an overview of Javascript types and variables.&lt;br&gt;&lt;br&gt;
In the next article from this series, I will cover the Number data type in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ganeshjaiwal/how-does-javascript-work-45oc"&gt;← How does JavaScript work? 🤔&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How does JavaScript work? 🤔</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Tue, 20 Oct 2020 14:46:47 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/how-does-javascript-work-45oc</link>
      <guid>https://dev.to/ganeshjaiwal/how-does-javascript-work-45oc</guid>
      <description>&lt;p&gt;Did you know the simple statement of JavaScript needs a lot of work done behind the seen to get it executed?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603173176592%2F6DsznxSKO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603173176592%2F6DsznxSKO.png" alt="JS Engine.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hmm…&lt;br&gt;
So the browser doesn’t understand javascript directly.&lt;br&gt;
Then how are we going to ask the browser to do something?&lt;/p&gt;

&lt;p&gt;Let’s start with what language the browser understands.&lt;br&gt;
The browser only understands 0s and 1s language i.e. Statements in Binary/Bits format.&lt;/p&gt;

&lt;p&gt;We can’t convert our whole JavaScript into bits easily. So what should we do now? 🤔&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;JavaScript engine:-&lt;/strong&gt; “Hey don’t worry I can help you with that give me your JavaScript file“.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  What is a JavaScript engine then?
&lt;/h2&gt;

&lt;p&gt;When a JavaScript file is loaded into the browser, JavaScript Engine executes that file line by line from top to bottom (Async code will be the exception, we will see async later in this series).&lt;br&gt;
JavaScript Engine will parse the code line by line and convert that code into the machine code (Binary/Bits format).&lt;/p&gt;

&lt;p&gt;Now browser can understand this machine code and behave accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some JS engine examples.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174045778%2Fb18xPTJ27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174045778%2Fb18xPTJ27.png" alt="JS Engine List.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Correction:-
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;With the Edge 79 release, Microsoft is switching to a Blink browser engine with a V8 JavaScript engine.&lt;/p&gt;

&lt;p&gt;Both Blink and V8 are developed under Chromium—an open-source project with an open-source web browser of the same name. &lt;strong&gt;Chromium—the open-source browser—is used by Google for its own Chrome browser. Now, Microsoft's Chromium Edge will do the same.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  So what is inside this javascript engine?
&lt;/h3&gt;

&lt;p&gt;Here is a very basic view of JavaScript Engine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174151494%2FBSotGJbGx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174151494%2FBSotGJbGx.png" alt="Untitled Diagram (5).png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Memory heap
&lt;/h2&gt;

&lt;p&gt;JavaScript engine is sometimes unable to allocate memory at compile-time, so variables that allocated at runtime go into memory heap (unstructured region of memory).&lt;br&gt;
Data/Objects that we allocate in the heap section exist even after we exit the function which allocated the memory inside the heap.&lt;/p&gt;

&lt;p&gt;Here we face a major problem of &lt;strong&gt;memory leak&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  So what is a memory leak?
&lt;/h3&gt;

&lt;p&gt;A memory heap has limited space.&lt;br&gt;
If we keep using heap space without caring about freeing up unused memory. This causes a memory leak issue when there is no more memory available inside the heap.&lt;/p&gt;

&lt;p&gt;To fix this issue javascript engine introduced a &lt;strong&gt;Garbage collector&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a Garbage collector?
&lt;/h3&gt;

&lt;p&gt;Garbage collection is a form of memory management. It’s like a collector which attempts to release the memory occupied by objects that are no longer being used. In other words, when a variable loses all its references Garbage collection marks this memory as “unreachable” and releases it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Execution context stack
&lt;/h2&gt;

&lt;p&gt;A stack is the data structure that follows the &lt;strong&gt;Last In First Out (LIFO)&lt;/strong&gt; principle (the last item to enter the stack will be the first item to be removed from the stack).&lt;/p&gt;

&lt;p&gt;ECS stores execution context for all the functions. Execution context is defined as an object which stores local variables, functions, and objects.&lt;/p&gt;

&lt;p&gt;In simple words, each function is pushed on the top of the sack.&lt;br&gt;
JavaScript engine executes the function which is at the top of this stack.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As JavaScript engine has only one ECS, it can execute only one thing at a time which is at the top of the ECS. This is what makes JavaScript single-threaded.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  You must have heard of stack overflow.
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;What does that mean?&lt;/em&gt; - ECS also has limited space. So, if we keep adding function on the top of the stack. At some point, there will not be more space to add more stack frames. At this point, we get a stack overflow error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consider the following example.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function heyJS() {
    console.log("Hello you are awesome!!!!");
    heyJS();
}
heyJS();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174818218%2FGH2wkzTGX.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174818218%2FGH2wkzTGX.png" alt="stack.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, that went into an infinite recursion and we have a stack overflow error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174998694%2FxSUYLvShJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603174998694%2FxSUYLvShJ.png" alt="Screenshot 2020-10-20 115250.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So as I mentioned JavaScript is a simple threaded language, which means it has only one call stack ad therefore it can only execute one statement at a time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Wait, we also heard about asynchronous programming in javascript.&lt;br&gt;
So how does that work when only one task is allowed at a time?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here comes &lt;strong&gt;Web API’s&lt;/strong&gt; and &lt;strong&gt;Callback queue&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Web API’s
&lt;/h3&gt;

&lt;p&gt;Web APIs are not part of the JS engine but they are part of the JavaScript Runtime Environment which is provided by the browser. JavaScript just provides us with a mechanism to access these API’s. As Web APIs are browser-specific, they may vary from browser to browser. There may be cases where some Web APIs may be present in one browser but not in another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;

&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById();
document.addEventListerner();
setTimeOut();
setInterval();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Example:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(“First!”);

setTimeout(() =&amp;gt; {
    console.log(“Second!”);
}, 1000 );

console.log(“Third!”);
/*
OutPut:- 
First
Third
Second
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s weird, right?&lt;/p&gt;

&lt;p&gt;“Second” is inside the setTimeout so that will executed after 1 second.&lt;/p&gt;

&lt;h3&gt;
  
  
  What exactly happens behind the scene?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175477527%2FqzKxYLD3t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175477527%2FqzKxYLD3t.png" alt="Untitled Diagram (4).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175510508%2F_bYI7aSVA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175510508%2F_bYI7aSVA.png" alt="Untitled Diagram (9).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175536411%2FOO5BrqdSe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175536411%2FOO5BrqdSe.png" alt="Untitled Diagram (7).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After 1-second WebAPI will get notified, &lt;em&gt;hey you have code that you need to execute now.&lt;/em&gt;&lt;br&gt;
WebAPI &lt;em&gt;“Oh it’s console.log() I need to execute that, but I can’t execute this directly. Let’s send it to Callback Queue”&lt;/em&gt;&lt;br&gt;
&lt;em&gt;“Hey, Queue here is the callback please add this on your list and execute it”.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Callback Queue
&lt;/h2&gt;

&lt;p&gt;Callback Queue or Message Queue is a queue data structure that follows the First In First Out principle (item to be inserted first in the queue will be removed from the queue first). It stores all the messages which are moved from the event table to the event queue. Each message has an associated function. The callback queue maintains the order in which the message or methods were added in the queue.&lt;/p&gt;
&lt;h2&gt;
  
  
  Event loop
&lt;/h2&gt;

&lt;p&gt;The event loop continuously checks if the execution context stack is empty and if there are any messages in the event queue. It will move the method from the callback queue to ECS only when the execution context stack is empty.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback Queue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Hey, Event loop please check if ECS is empty. I have some callbacks that you need to push into ECS”.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Queue please give me callbacks ECS is empty now, I will push them on the stack to execute them.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175984495%2FiBzp_rgUe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1603175984495%2FiBzp_rgUe.png" alt="Untitled Diagram (8).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally, in the end, we will get out output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// First
// Third
// Second
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just an overview of how JavaScript Engine works.&lt;/p&gt;

&lt;p&gt;JavaScript engine is way more complex than how we discuss here today.&lt;/p&gt;

&lt;p&gt;I will try to get deeper into the JavaScript engine in some of my future Articles.&lt;/p&gt;

&lt;p&gt;In the next article of this series, I will explain Javascript Types, values, and variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ganeshjaiwal/introduction-to-javascript-1j98"&gt;← Introduction to JavaScript&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Introduction to JavaScript</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Tue, 13 Oct 2020 11:58:35 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/introduction-to-javascript-1j98</link>
      <guid>https://dev.to/ganeshjaiwal/introduction-to-javascript-1j98</guid>
      <description>&lt;p&gt;JavaScript is a scripting or programming language that allows you to implement complex features on web pages.&lt;/p&gt;

&lt;h4&gt;
  
  
  What does the above statement exactly mean?
&lt;/h4&gt;

&lt;p&gt;JavaScript provides us a way to make webpages interactive. Whatever action we perform on the web page to make it do something, is handled using JavaScript.&lt;br&gt;
Without JavaScript, a web page is just a showcase. We can’t do anything with that except keep looking at it or loading different pages inside the browser.&lt;/p&gt;

&lt;p&gt;If you are familiar with any other programming language, you can assess that Javascript is a dynamic and high-level Interpreted programming language.&lt;/p&gt;

&lt;p&gt;The best way to learn any programming language is to keep practicing, keep coding.&lt;/p&gt;

&lt;p&gt;The simplest way to try JavaScript examples is by using browsers' dev tools.&lt;br&gt;
To open dev tools there are various options,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;F12&lt;/li&gt;
&lt;li&gt;Ctrl+Shift-I / Command+Options+I&lt;/li&gt;
&lt;li&gt;Right click -&amp;gt; Inspect Element&lt;/li&gt;
&lt;li&gt;Browser options and find Developer tools option&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you open the dev tools panel select Console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PUEMS3mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602131469222/PkxFSiBTz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PUEMS3mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602131469222/PkxFSiBTz.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now inside the console, we can run any JavaScript statement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--olQaBsff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602131491341/C1IzgnRn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--olQaBsff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602131491341/C1IzgnRn9.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Once you are done practicing small snippets, now it time to work with large/long code snippets.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consider creating 2 files,&lt;/strong&gt;&lt;br&gt;
    1. hello.html&lt;br&gt;
    2. hello.js&lt;/p&gt;

&lt;p&gt;Add the following code snippets to respective files.&lt;/p&gt;

&lt;h4&gt;
  
  
  hello.js
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(“Hello world!”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  hello.html
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="UTF-8"&amp;gt;
        &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;script src="hello.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Keep both files at the same location.&lt;br&gt;
Then load hello.html into your web browser using a file://URL &lt;br&gt;
Open the console, you will see the message “Hello World!”.&lt;/p&gt;

&lt;p&gt;🎉 Bingo!!!!&lt;br&gt;
We just ran our first JavaScript file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s check out some more details about JavaScript
&lt;/h3&gt;

&lt;h4&gt;
  
  
  JavaScript is a case sensitive language.
&lt;/h4&gt;

&lt;p&gt;What does this mean?&lt;br&gt;
This means all language keywords, variables, function names, and identifiers should be typed/used with proper case.&lt;/p&gt;

&lt;h4&gt;
  
  
  For example:-
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var count = 0;
var Count = 0;
var COUNT = 0;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;All of the above variables are referred to as different variables.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Comments:-
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JavaScript supports two types of comments.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Anything written between // and the end of the line is treated as a comment and is ignored by JavaScript.&lt;/p&gt;

&lt;p&gt;Another way to add a comment is a multi-line comment.&lt;br&gt;
Add your comment in between /* and */&lt;/p&gt;

&lt;h4&gt;
  
  
  Examples:-
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Single line comment

/* 
Multi-line comment
*/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Identifiers:-
&lt;/h3&gt;

&lt;p&gt;It is a simple name used to represent any variable, function, class, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Identifier rules:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;The identifier should start with character.&lt;/li&gt;
&lt;li&gt;The identifier doesn’t allow special characters&lt;/li&gt;
&lt;li&gt;An identifier should not start with a digit.&lt;/li&gt;
&lt;li&gt;_ is considered a valid character to create an identifier.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Reserved keywords:-
&lt;/h3&gt;

&lt;p&gt;The words that are reserved for language and not allowed for general use as an identifier are known as reserved keywords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for&lt;/li&gt;
&lt;li&gt;async&lt;/li&gt;
&lt;li&gt;if&lt;/li&gt;
&lt;li&gt;switch&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Optional semicolon:-
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Using semicolons are not compulsory in JavaScript.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can omit a semicolon at the end of the statement, JavaScript automatically inserts a semicolon if we didn’t add one.&lt;/p&gt;

&lt;p&gt;That’s it for this article.&lt;/p&gt;

&lt;p&gt;In the next article, we will look into &lt;strong&gt;How does JavaScript work.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Until then keep practicing, keep coding…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you liked it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Automate Chrome extension publish using an automated script</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Mon, 05 Oct 2020 12:50:39 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/automate-chrome-extension-publish-using-an-automated-script-3a7c</link>
      <guid>https://dev.to/ganeshjaiwal/automate-chrome-extension-publish-using-an-automated-script-3a7c</guid>
      <description>&lt;p&gt;We are living in a world where everything is automated, so why publish Chrome extension manually?🤔&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s automate our process of publishing the chrome extension that we set up in the  &lt;a href="https://dev.to/ganeshjaiwal/how-to-publish-your-chrome-extension-2obn"&gt;previous article&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This article is going to be long but in the end, you will have great things in your hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this article I will be going to focus mainly on the following topics:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Let’s change our extension folder structure
&lt;/li&gt;
&lt;li&gt; Setup package.json file to install required NPM packages &lt;/li&gt;
&lt;li&gt; Setting up Github actions to automate deployment on code push &lt;/li&gt;
&lt;li&gt; Let’s set up Google credentials to allow uploading extension &lt;/li&gt;
&lt;li&gt; Write a script to publish an extension to web-store

&lt;ul&gt;
&lt;li&gt;Include required packages&lt;/li&gt;
&lt;li&gt;Setup build path&lt;/li&gt;
&lt;li&gt;Update extension version&lt;/li&gt;
&lt;li&gt;Generate a zip file to upload to store&lt;/li&gt;
&lt;li&gt;Initialize webstore with client Id and client secret&lt;/li&gt;
&lt;li&gt;Generating new refresh token&lt;/li&gt;
&lt;li&gt;Upload extension zip to store&lt;/li&gt;
&lt;li&gt;Publish Extension&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Let’s change our extension folder structure
&lt;/h3&gt;

&lt;p&gt;Before we start let’s rearrange our extension folder structure that we created in  &lt;a href="https://dev.to/ganeshjaiwal/build-your-first-chrome-extension-458g"&gt;Getting started with the chrome extension&lt;/a&gt;.&lt;br&gt;
This will help us to manage our code and to create extension zip in upcoming steps. To do this create a new folder in our project directory &lt;code&gt;[app]&lt;/code&gt; and move all the extension files into the &lt;code&gt;[app]&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can change this according to your need if you are using any build tool like webpack.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wLODyD6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601648224452/Il_95fg2R.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wLODyD6A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601648224452/Il_95fg2R.png" alt="updated folder structure"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setup package.json file to install required NPM packages
&lt;/h3&gt;

&lt;p&gt;Now it's time to use some npm packages which will help us to automate our process.&lt;br&gt;
Using these packages will reduce our efforts and make things easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Packages that we need:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;jsonfile&lt;/strong&gt; -  &lt;a href="https://www.npmjs.com/package/jsonfile"&gt;npm -&amp;gt;&lt;/a&gt; 
This will help us to read the manifest.json file to update the version of our extension.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;zip-local&lt;/strong&gt; -  &lt;a href="https://www.npmjs.com/package/zip-local"&gt;npm -&amp;gt;&lt;/a&gt; 
We will use this to generate a zip file of our code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fs-extra&lt;/strong&gt; -  &lt;a href="https://www.npmjs.com/package/fs-extra"&gt;npm -&amp;gt;&lt;/a&gt;
fs-extra will help us to read our zip file into the buffer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;chrome-webstore-manager&lt;/strong&gt; -  &lt;a href="https://www.npmjs.com/package/chrome-webstore-manager"&gt;npm -&amp;gt;&lt;/a&gt;
This is the most important package we need to automate our process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;path&lt;/strong&gt; - It is by default provided by Node.js so no need to install it explicitly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Now let’s make the way to get it done using package.json
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is the package.json file?&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.&lt;br&gt;
To know more click  &lt;a href="https://nodejs.org/en/knowledge/getting-started/npm/what-is-the-file-package-json"&gt;here&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To create and initialize the package.json file run the following command in terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Use default options or add details according to your need.&lt;/p&gt;

&lt;p&gt;Once you've created package.json, it’s time to install our dependencies that I mentioned above.&lt;br&gt;
To do so run the following command:-&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install jsonfile zip-local fs-extra chrome-webstore-manager --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Save-dev&lt;/strong&gt; - This option will save our dependencies in package.json under the devDependencies property.&lt;/p&gt;

&lt;p&gt;Here is the final structure of the package.json&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Setting up Github actions to automate deployment on code push
&lt;/h3&gt;

&lt;p&gt;GitHub action allows us to add an automated task. This task will run when specific actions get triggered on the GitHub repo.&lt;br&gt;
In our case, we need to run some npm commands to deploy our extension by running our node.js script.&lt;/p&gt;

&lt;p&gt;To know more about git hub actions click  &lt;a href="https://docs.github.com/en/free-pro-team@latest/actions"&gt;here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here is the example of GitHub action that we need.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Add this file as it is to GitHub action.&lt;/p&gt;

&lt;p&gt;Where to add this file?🤔&lt;br&gt;
Create the following folder structure to add an action workflow file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt; Chrome-extension-demo
    -&amp;gt; app  //Our extension code
    -&amp;gt; .github
        -&amp;gt; workflows
            -&amp;gt; action.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Let’s set up Google credentials to allow uploading extension
&lt;/h3&gt;

&lt;p&gt;To automate publishing, you need to enable the Chrome Web Store API for your project in the Google Developers Console.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit the Google Developers Console.&lt;/li&gt;
&lt;li&gt;Create a new project or select an existing one.&lt;/li&gt;
&lt;li&gt;In the sidebar on the left, select APIs &amp;amp; auth.&lt;/li&gt;
&lt;li&gt;In the displayed list of available APIs, set the status of the Chrome Web Store API to ON.&lt;/li&gt;
&lt;li&gt;Accept the Terms of Service.&lt;/li&gt;
&lt;li&gt;In the sidebar on the left, select Credentials.&lt;/li&gt;
&lt;li&gt;To create the client ID and client secret

&lt;ul&gt;
&lt;li&gt;Click on &lt;em&gt;Create Credentials&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;Select  &lt;em&gt;OAuth client ID&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Desktop App&lt;/em&gt; under application type&lt;/li&gt;
&lt;li&gt;Enter the name of your application&lt;/li&gt;
&lt;li&gt;Click on the Create button. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🥳 &lt;strong&gt;Yeah!&lt;/strong&gt;  We got the &lt;strong&gt;client Id&lt;/strong&gt; and &lt;strong&gt;client secret&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aToEhtx2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601654101729/aGfRzgdRh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aToEhtx2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601654101729/aGfRzgdRh.png" alt="MyProject – Google API Console.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get an access token:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you have the client ID and client secret, you can retrieve an access token and refresh token. The access token is responsible for authorizing our script to upload and publish an extension.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note:- Access token gets expired after 40 minutes. So, we will always need to create a new one while deploying our extension in a continuous deployment process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To create new access_token we will use refresh_token.&lt;/p&gt;

&lt;h4&gt;
  
  
  Let’s generate access_token and refresh_token:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Use the following URL to generate code which is used to generate access_token
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://accounts.google.com/o/oauth2/auth?response_type=code&amp;amp;scope=https://www.googleapis.com/auth/chromewebstore&amp;amp;client_id=$CLIENT_ID&amp;amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;$CLIENT_ID&lt;/strong&gt; with the client Id that we generated in the previous step.&lt;br&gt;
Paste the updated URL in the browser and hit enter.&lt;br&gt;
Select the same google account where you have an extension uploaded.&lt;br&gt;
Grant permission to view and manage your chrome extension and apps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m4iculXt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601656386459/wn9R4ZbjW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m4iculXt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601656386459/wn9R4ZbjW.png" alt="Grand permission.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;After granting permission we get the authorization code.
Copy that code to generate access_token.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NqteOuWX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601656473097/YHvKCurFE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NqteOuWX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1601656473097/YHvKCurFE.png" alt="token.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal to execute the next curl request.
Use above code to request an access token. For example, using curl, you can get an access token by executing the following command (replacing the values of $CLIENT_ID, $CLIENT_SECRET, and $CODE with the values from above):
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl "https://accounts.google.com/o/oauth2/token" -d \
"client_id=$CLIENT_ID&amp;amp;client_secret=$CLIENT_SECRET&amp;amp;code=$CODE&amp;amp;grant_type=authorization_code&amp;amp;redirect_uri=urn:ietf:wg:oauth:2.0:oob"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;This will return a result such as:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "access_token" : "ya29...",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/rwn..."
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note down the refresh token we will use this token in our deploy script.&lt;/p&gt;

&lt;h3&gt;
  
  
  Write a script to publish an extension to web-store
&lt;/h3&gt;

&lt;p&gt;Create a new JavaScript file at the root level of our extension and name it as deploy.js&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Include the required packages
Import packages that we installed using NPM.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs-extra');
const zipper = require("zip-local");
const jsonfile = require('jsonfile');
const path = require('path');
const ChromeWebstore = require('chrome-webstore-manager');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Setup build path
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const itemId = "EXTENSION_ID";
var buildLocation = path.join(__dirname, "app");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Replace EXTENSION_ID with Id of the extension that uploaded in the  &lt;a href="https://dev.to/ganeshjaiwal/how-to-publish-your-chrome-extension-2obn"&gt;previous article&lt;/a&gt;&lt;br&gt;
Id may look like:- &lt;code&gt;ecjchthpmtdecenmykiuipbibkhcijlj&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update extension version 
While uploading a new package to the store add a new version. Google does not allow uploading a new package with the same version. 
&lt;strong&gt;Read manifest file&lt;/strong&gt;
&lt;strong&gt;Generate new version&lt;/strong&gt;
&lt;strong&gt;Update with the new version&lt;/strong&gt;
&lt;strong&gt;Write manifest file with an updated version&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// read manifest file
var manifest = jsonfile.readFileSync(path.join(buildLocation, "manifest.json"));
function getNewVersion() {
       var ver = parseInt(manifest.version.split('.')[0]);
       ver++;
       return `${ver}.0.0`;
}
var version = getNewVersion();
// replace version
manifest.version = version;
// save manifest file
jsonfile.writeFileSync(path.join(buildLocation, "manifest.json"), manifest);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Generate a zip file and read that file to upload to store
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// create zip
zipper.sync.zip(buildLocation).compress().save(path.join(buildLocation, "build.zip"));
const fileBin = fs.readFileSync(path.join(buildLocation, "build.zip"));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Initialize webstore with client Id and client secret
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize with ClientID and ClinetSecret
const chromeWebstore = new ChromeWebstore("&amp;lt;CLIENT_ID&amp;gt;", "&amp;lt;CLIENT_SECRET&amp;gt;");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Replace CLIENT_ID and CLIENT_SECRET with values that we created before.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generating new access_token
Use the following function to create new access_token.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chromeWebstore.getRefreshToken("&amp;lt;REFRESH_TOKEN&amp;gt;")
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Replace REFRESH_TOKEN with refresh_token that we generated in the previous process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upload extension zip to store
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chromeWebstore.updateItem(newToken, fileBin, itemId)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the 6th step, we will get a promise, which returns an object containing new access_token.&lt;br&gt;
Use this access token to upload extension zip with the update method of chromeWebstore.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Publish Extension
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chromeWebstore.publishItem(newToken, itemId)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once the upload is done we are ready to publish our extension.&lt;br&gt;
To publish we are going to use chromeWebstore’s publishItem method.&lt;/p&gt;

&lt;h4&gt;
  
  
  Let’s keep the last 3 steps together to complete our script.
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Get new token with refresh_token
chromeWebstore.getRefreshToken("&amp;lt;REFRESH_TOKEN&amp;gt;").then(function (data) {
   const json = JSON.parse(data)
   const newToken = json.access_token
   chromeWebstore.updateItem(newToken, fileBin, itemId).then((data) =&amp;gt; {
       console.log(data);
       chromeWebstore.publishItem(newToken, itemId).then((data) =&amp;gt; {
           console.log(data);
       });
   });
});
console.log("Deployed version is " + version);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Hoorayyyyy! 🎉🎉
&lt;/h4&gt;

&lt;p&gt;Finally, we are done with creating our deploy script.&lt;/p&gt;

&lt;p&gt;Now once we push our extension code into the repo, Github Action will get triggered.&lt;br&gt;
In our workflow file, we wrote a command that triggers the deploy script, and the extension will get updated using the deploy script &lt;strong&gt;automatically&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This was a long article as I had a lot of explaining to do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you liked it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope you like it, if yes **like &amp;amp; share.**&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding….&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to publish your Chrome Extension</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Sat, 05 Sep 2020 18:04:48 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/how-to-publish-your-chrome-extension-2obn</link>
      <guid>https://dev.to/ganeshjaiwal/how-to-publish-your-chrome-extension-2obn</guid>
      <description>&lt;p&gt;In my previous article, I covered how to &lt;a href="https://dev.to/ganeshjaiwal/build-your-first-chrome-extension-458g"&gt;Build your first chrome extension&lt;/a&gt; in detail.&lt;/p&gt;

&lt;p&gt;Now publish that extension to the &lt;a href="https://chrome.google.com/webstore/category/extensions" rel="noopener noreferrer"&gt;chrome web store&lt;/a&gt; so that other users can download and use the service that we have developed in the previous article.&lt;/p&gt;

&lt;p&gt;Google made the process of publishing extension very easy by providing a &lt;a href="https://chrome.google.com/u/1/webstore/devconsole/" rel="noopener noreferrer"&gt;developer dashboard&lt;/a&gt;.👨🏻‍💻&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let's jump into the actual steps.&lt;/strong&gt;🧐
&lt;/h3&gt;

&lt;p&gt;To publish our item to the Chrome Web Store, we will follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create your extension's zip file&lt;/li&gt;
&lt;li&gt;Create a developer account and Activate an account&lt;/li&gt;
&lt;li&gt;Upload your package&lt;/li&gt;
&lt;li&gt;Add details about your extension&lt;/li&gt;
&lt;li&gt;Add assets for your listing&lt;/li&gt;
&lt;li&gt;Submit your item for publishing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Stick together and let's get into detail about each step.&lt;/em&gt;🤝🏻&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create our extension's zip file&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To publish our extension we need to create a zip file that includes all the necessary files.&lt;/p&gt;

&lt;p&gt;📝&lt;strong&gt;Note:-&lt;/strong&gt; &lt;em&gt;manifest.json&lt;/em&gt; must be included in the package at the root level, and the manifest file must contain the following fields.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Name” — Used to represent the name of the extension on the Web Store and Chrome&lt;/li&gt;
&lt;li&gt;“Version” — This represents the version of the extension (incrementing value)&lt;/li&gt;
&lt;li&gt;“Icon” — This represents the extension’s display icon on Web Store and Chrome&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Refer to the following file structure for other required files.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff4evls6pdosklaors0c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff4evls6pdosklaors0c3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To upload a package created in the previous step you need a developer account, so let’s create one.✏️&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Create a developer account and Activate an account&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Before we publish our Chrome extension to the web store, we need to &lt;a href="https://chrome.google.com/webstore/devconsole/register" rel="noopener noreferrer"&gt;register as a Chrome Web Store developer&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;On your developer account, the email address field is required. You cannot publish items if this field is blank.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To register ourselves as a developer, we need to visit the developer console.&lt;br&gt;
Then we need to agree to the Developer’s agreement and policies.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;As you can see in the following image, we need to pay $5💰 as a lifetime developer account fee (to publish our extension this is required).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F516i6r4kt525ru862hab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F516i6r4kt525ru862hab.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we are done with activating our account now we can upload the package to the dashboard that we created in the first step.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Let’s Upload our package&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To upload our package we need to create a new item on the dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwggst2vq1si9mstbbq2k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwggst2vq1si9mstbbq2k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the New Item button which will open one small popup, use this popup to upload a zip file that we have created. We can upload our item multiple times before submitting it for review.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F82k1h6w8pm65k44jw18y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F82k1h6w8pm65k44jw18y.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You cannot have more than 20 extensions published on the Chrome Web Store. There is no such limit on the number of themes.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;⚠️ &lt;em&gt;&lt;strong&gt;Be aware that once you add an extension to your Developer Dashboard you cannot delete it. As long as it is not published, it will not count towards your extension limit.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Let’s add details about our extension&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;After a successful package upload, we will be redirected to the page where we need to fill all the necessary additional details about our chrome extension.&lt;/p&gt;

&lt;p&gt;First, we will select &lt;strong&gt;“Store Listing”&lt;/strong&gt; options from the left menu,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let’s add a description to our item in the description section.&lt;/li&gt;
&lt;li&gt;Then select the category for your extension (this is to list our extension on the web-store under the selected category).&lt;/li&gt;
&lt;li&gt;Select the preferred language for our extension.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd7qyev2dfuhmsvvlu4yb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd7qyev2dfuhmsvvlu4yb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are using any special permissions in your manifest file then you will need to add some description about that permission in the &lt;strong&gt;privacy section&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmw1eqsa576px831duw0p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmw1eqsa576px831duw0p.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Let’s add assets for our listing&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Once we are done with adding details, we need to add some assets for our listing,&lt;br&gt;
Assets are nothing but the showcase or a quick view of our extension.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We can add a youtube video or any images of a specific size.&lt;br&gt;
We need to add at least one image as assets to publish our extension.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frwckgucsuwsm3urf88xk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frwckgucsuwsm3urf88xk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Other details can be added but I am not going to cover everything in this article as this is our first extension and we don’t need them here.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Submit our item for publishing📢&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;And now everything is set to publish our first extension.🥳&lt;br&gt;
After adding all the details and necessary information save the changes.&lt;/p&gt;

&lt;p&gt;If nothing is remaining from compulsory fields, then the submit for review button will get enabled.&lt;/p&gt;

&lt;p&gt;We can click the Submit for Review button and submit our first chrome extension for review.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The following dialog appears, letting us confirm that we want to submit the item for review.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuen3px2m09xo2k0xckcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuen3px2m09xo2k0xckcy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The confirmation dialog is shown above also lets us control the timing of our item’s publishing. If we uncheck the checkbox, our item will not be published immediately after its review is complete. Instead, we’ll be able to manually publish it whenever we want once the review is complete.&lt;/p&gt;

&lt;p&gt;So let’s click the last button (Submit for review) to put a final step towards publishing the extension.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;After we submit the item for review, it will undergo a review process. The time for this review depends on the nature of our item, once that is done our extension will be live on Chrome Web Store.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bingo!🤩 We just published our first chrome extension.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the upcoming article, I’ll explain how to upload/update our extension using an automated script.&lt;/p&gt;

&lt;p&gt;Stay connected!&lt;/p&gt;

&lt;p&gt;Hope you liked it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Hope you like it, if yes *❤️ &amp;amp; Share.&lt;/strong&gt;*&lt;br&gt;
&lt;strong&gt;Happy coding ...&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Build Your First Chrome Extension</title>
      <dc:creator>Ganesh Jaiwal</dc:creator>
      <pubDate>Thu, 03 Sep 2020 10:23:01 +0000</pubDate>
      <link>https://dev.to/ganeshjaiwal/build-your-first-chrome-extension-458g</link>
      <guid>https://dev.to/ganeshjaiwal/build-your-first-chrome-extension-458g</guid>
      <description>&lt;p&gt;I hope all of you are doing well.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you are interested in knowing how browser extensions work and how to build your very first chrome extension, then YES you are at the right place.&lt;/em&gt;😎&lt;/p&gt;

&lt;p&gt;In this article, let’s stick together to build your own brand new chrome extension.&lt;/p&gt;

&lt;p&gt;Before we start, let’s look into some important terminologies.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is an extension? 🧐
&lt;/h3&gt;

&lt;p&gt;“Extension” The name itself explains a lot,&lt;br&gt;
It is something¹ that enhances or “extends” the capabilities of something².&lt;br&gt;
In our case, the first something is a package consisting of a set of different files that are bundled together to make it a single entity called browser extension.&lt;br&gt;
And second, something is of which we want to enhance the functionality or say capability of web browsers.&lt;/p&gt;

&lt;p&gt;So let’s see,&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Web Browsers?
&lt;/h3&gt;

&lt;p&gt;A web browser is the most important part of everyone’s life nowadays. I can’t even imagine my life without a web browser being a software developer 👨🏻‍💻 (We use it a lot).&lt;br&gt;
According to Wikipedia, a web browser (commonly referred to as a browser) is a software application for accessing the information on the World Wide Web. When a user requests a web page from a particular website, the web browser retrieves the necessary content from a web server and then displays the page on the screen.&lt;/p&gt;
&lt;h4&gt;
  
  
  How extension helps web browsers(Focusing on Google Chrome)?🤔
&lt;/h4&gt;

&lt;p&gt;I think extensions are a very important part of browsers.&lt;br&gt;
In my opinion, I love to use extensions that make my life easier and productive.&lt;br&gt;
The extension that I use a lot is &lt;a href="https://bit.ly/lastpass-ext" rel="noopener noreferrer"&gt;&lt;code&gt;LastPass&lt;/code&gt;&lt;/a&gt;. This extension remembers credentials on my behalf and lets my brain focus on more important stuff rather than remembering complex passwords 😉&lt;br&gt;
I have to save the credentials only for the first time I log in.&lt;/p&gt;

&lt;p&gt;Consider one case study in which you want to get all products and its price listing in a short time.&lt;br&gt;
If you are using a plain web browser, then you need to do that manually.&lt;br&gt;
Sounds like a lot to work right? But what if you create one extension once and install it into the browser. You just need to click once and all listings will be done by the extension for you in a well-formatted way.&lt;/p&gt;

&lt;p&gt;Well, for that you must know how to build browser extensions, let’s check it out then.&lt;br&gt;
&lt;strong&gt;...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbjq0qgcr1rn6ihre18zo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbjq0qgcr1rn6ihre18zo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Before starting to build chrome extensions let’s know more about its basics.&lt;/p&gt;

&lt;p&gt;The attached image shows all the important parts of the extension.&lt;/p&gt;

&lt;p&gt;There are some important parts of an extension without which you can’t build one.&lt;br&gt;
So, let’s check them out first.&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;em&gt;Manifest File&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;This is the most important and necessary file while creating browser extensions.&lt;br&gt;
The manifest file is the JSON object of extension metadata which holds all the basic information for the extensions.&lt;br&gt;
Check out the sample of the &lt;a href="https://bit.ly/chrome-manifest" rel="noopener noreferrer"&gt;&lt;code&gt;Manifest file&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h5&gt;
  
  
  &lt;em&gt;Background Script&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;Background Script is a JavaScript file that runs in the background to handle browser events. It is also known as the extension’s event handler page. It is responsible for handling the browser's events such as on bookmark create, on page load completed, etc.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h5&gt;
  
  
  &lt;em&gt;Extension Popup&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;A pop up is an HTML file that is displayed in a special window when the user clicks the toolbar icon. It works in a very similar way compared to a web page; it can contain links to stylesheets and script tags but does not allow inline JavaScript.&lt;br&gt;
Check the extension popup code &lt;a href="https://bit.ly/chrome-popup" rel="noopener noreferrer"&gt;&lt;code&gt;here&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu5r3x0ph4qbcsmojrhdr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu5r3x0ph4qbcsmojrhdr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;em&gt;Content Script&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;This is the JavaScript file that is injected into the web page to perform operations such as accessing the details of the web pages, make changes to them, and pass information to their parent extension.&lt;br&gt;
You can configure manifest file using options like:&lt;br&gt;
&lt;code&gt;run_at&lt;/code&gt; used to decide when to inject and execute the script.&lt;br&gt;
&lt;code&gt;matches&lt;/code&gt; responsible for deciding where to inject script on the basis of URL pattern matching.&lt;br&gt;
&lt;code&gt;js&lt;/code&gt; An array of JS file paths to be injected.&lt;br&gt;
&lt;code&gt;css&lt;/code&gt; An array of style sheet file paths to be injected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.chrome.com/extensions/content_scripts#declaratively" rel="noopener noreferrer"&gt;&lt;code&gt;(Check manifest content script entry)&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Check the image below which shows that div is injected by the content script on the top of the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fran2rpkwfkh8ps45locq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fran2rpkwfkh8ps45locq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h5&gt;
  
  
  &lt;em&gt;Options Page&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;Allow users to customize the behaviour of an extension by providing an options page. A user can view the extension’s options by right-clicking the extension icon in the toolbar and then selecting options. Another way to navigate to the extension management page at chrome://extensions and then selecting Details on the desired extension. In the details page select the options link.&lt;br&gt;
Check the options page code &lt;a href="https://bit.ly/chrome-options" rel="noopener noreferrer"&gt;&lt;code&gt;here&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Keep it all together to create your very first chrome extension.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Great! We are done with creating our first chrome extension, now it’s time to test our extension in developer mode.&lt;/em&gt;🥳&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Load extension to chrome browser by visiting chrome://extensions.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visit Chrome://extensions&lt;/li&gt;
&lt;li&gt;Enable Developer mode toggle switch (placed at the top right corner) to see developer options on the same page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Far32glfgxruseaf1nsoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Far32glfgxruseaf1nsoe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the load unpacked button (placed in the top left corner).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F69eq50ej25jbj3d6kwhy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F69eq50ej25jbj3d6kwhy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select your extension folder to load extension to the browser. (Make sure manifest.json is at the root level).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bingo! 🤩 You just created and ran your very first chrome extension.&lt;/p&gt;

&lt;p&gt;Get code for the extension we just created from &lt;a href="https://bit.ly/chrome-ext-code" rel="noopener noreferrer"&gt;&lt;code&gt;here&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the upcoming article, I’ll explain how to upload your own extension to the chrome web store using two different approaches, manual and script-based.&lt;br&gt;
Stay connected!&lt;/p&gt;

&lt;p&gt;Hope you liked it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for your time.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Hope you like it, if yes *❤️ &amp;amp; Share.&lt;/strong&gt;*&lt;br&gt;
&lt;strong&gt;Happy coding ...&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>computerscience</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
