<?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: Anwar Gul</title>
    <description>The latest articles on DEV Community by Anwar Gul (@anwargul0x).</description>
    <link>https://dev.to/anwargul0x</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%2F242365%2F77e1bfb3-3347-41e4-8dd8-6a44b70cde42.jpg</url>
      <title>DEV Community: Anwar Gul</title>
      <link>https://dev.to/anwargul0x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anwargul0x"/>
    <language>en</language>
    <item>
      <title>Get Started with React Native + Google Sign In</title>
      <dc:creator>Anwar Gul</dc:creator>
      <pubDate>Sun, 19 Apr 2020 20:15:35 +0000</pubDate>
      <link>https://dev.to/anwargul0x/get-started-with-react-native-google-sign-in-18i5</link>
      <guid>https://dev.to/anwargul0x/get-started-with-react-native-google-sign-in-18i5</guid>
      <description>&lt;p&gt;In this post, I will be showing you guys how you can add sign in with Google feature in your app in a few simple steps.&lt;/p&gt;

&lt;p&gt;I will be using a React Native Community supported package called &lt;code&gt;react-native-community/google-signin&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Note :  &lt;code&gt;This post is made for react-native &amp;gt;= 0.60, if you are using react-native &amp;lt;= 0.59.x then this is not for you&lt;/code&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tPaiBzdH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/react-native-community/google-signin/raw/master/img/header.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tPaiBzdH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/react-native-community/google-signin/raw/master/img/header.png" alt="google-signin" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Support all 3 types of authentication methods (standard, with server-side validation or with offline access (aka server-side access))&lt;/li&gt;
&lt;li&gt;Promise-based API consistent between Android and iOS&lt;/li&gt;
&lt;li&gt;Typings for TypeScript and Flow&lt;/li&gt;
&lt;li&gt;Native signin buttons&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Versions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  React Native 0.61.5
&lt;/h4&gt;

&lt;h4&gt;
  
  
  react-native-community/google-signin 4.0.0
&lt;/h4&gt;

&lt;h1&gt;
  
  
  Steps
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;First, create the App using this command in terminal
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx react-native init TypeYourAppNameHere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Navigate to RNGoogleSignInDemo in the terminal like this
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;TypeYourAppNameHere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Now install &lt;code&gt;react-native-community/google-signin&lt;/code&gt; dependency in your app
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @react-native-community/google-signin

OR

npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @react-native-community/google-signin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Since React Native &amp;gt;= 0.60 &lt;code&gt;AutoLinking&lt;/code&gt; is supported therefore we don't need to run linking command.&lt;/p&gt;

&lt;p&gt;But we do need to do some configuration in the native side but I promise it will be easy.&lt;/p&gt;

&lt;p&gt;There are two ways to do this, with or without Firebase and I will be using the one with the Firebase. But for the other one, I can make a separate post for it. Do let me know should I?&lt;/p&gt;
&lt;h1&gt;
  
  
  Firebase
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Search for Firebase and go to Firebase Console&lt;/li&gt;
&lt;li&gt;Create a project [ I have already created ] by clicking on &lt;code&gt;Add Project&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zh1Mhq-F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.0.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zh1Mhq-F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.0.png%3Fraw%3Dtrue" alt="firebase console" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type your project Name after that click Continue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RgL67jwU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.1.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RgL67jwU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.1.png%3Fraw%3Dtrue" alt="firebase console" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose whether you want to add Analytics or not it's up to your preferences. By default, it's enabled. Press Continue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tgb1vRdp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.2.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tgb1vRdp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.2.png%3Fraw%3Dtrue" alt="firebase console" width="708" height="649"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now your project is created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SW5K62yk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.3.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SW5K62yk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.3.png%3Fraw%3Dtrue" alt="firebase console" width="706" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the android icon in the firebase Console Dashboard&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xFBdGB3u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.4.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xFBdGB3u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase1.4.png%3Fraw%3Dtrue" alt="firebase console" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Fill in the following fields of "Add Firebase to your Android app" to generate config file ( i.e. google-services.json)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android package name&lt;/li&gt;
&lt;li&gt;Debug signing certificate SHA-1
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--scl85aBq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.0.1.png%3Fraw%3Dtrue" alt="firebase console" width="800" height="507"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For App's Package name you can find in &lt;code&gt;android/app/main/AndroidManifest.xml&lt;/code&gt; file &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--whHUPlXF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase.2.1.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--whHUPlXF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase.2.1.png%3Fraw%3Dtrue" alt="AndroidManifest.xml" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For  Debug signing certificate SHA-1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In terminal type command for Debug SHA1 (root of the project) &lt;/p&gt;
&lt;h2&gt;
  
  
  Mac/Linux
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;keytool &lt;span class="nt"&gt;-J-Duser&lt;/span&gt;.language&lt;span class="o"&gt;=&lt;/span&gt;en &lt;span class="nt"&gt;-list&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-keystore&lt;/span&gt; ~/.android/debug.keystore &lt;span class="nt"&gt;-alias&lt;/span&gt; androiddebugkey &lt;span class="nt"&gt;-storepass&lt;/span&gt; android &lt;span class="nt"&gt;-keypass&lt;/span&gt; android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Windows
&lt;/h2&gt;

&lt;p&gt;– Change the directory to the JDK bin directory. The path of the JDK depends upon the operating system you are using&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;C:&lt;span class="se"&gt;\P&lt;/span&gt;rogram Files&lt;span class="se"&gt;\J&lt;/span&gt;ava&lt;span class="se"&gt;\j&lt;/span&gt;dk1.8.0_121&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;– Now we have to run the following command using the keytool.exe file in JDK/bin&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;keytool &lt;span class="nt"&gt;-list&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-keystore&lt;/span&gt; &lt;span class="s2"&gt;"%USERPROFILE%&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="s2"&gt;android&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="s2"&gt;ebug.keystore"&lt;/span&gt; &lt;span class="nt"&gt;-alias&lt;/span&gt; androiddebugkey &lt;span class="nt"&gt;-storepass&lt;/span&gt; android &lt;span class="nt"&gt;-keypass&lt;/span&gt; android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1fUy63GQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1fUy63GQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh1.png" alt="terminal" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you don't like terminal then you use can Android Studio instead&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T2i3B_zg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T2i3B_zg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh4.png" alt="Android Studio 1" width="800" height="263"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OgGcNJT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OgGcNJT9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://aboutreact.com/wp-content/uploads/2018/09/key_store_ssh6.png" alt="Android Studio 2" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you are done registering your android app with firebase then &lt;code&gt;Download the Config file&lt;/code&gt; and place it in &lt;code&gt;android/app&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LSc8KRsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.2.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LSc8KRsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.2.png%3Fraw%3Dtrue" alt="firebase2.2.png" width="800" height="409"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ijAw7rij--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase.2.2.1.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ijAw7rij--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase.2.2.1.png%3Fraw%3Dtrue" alt="firebase2.2.1.png" width="347" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add Firebase SDK in Project-level build.gradle  i.e. &lt;code&gt;android/build.gradle&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5kP4UEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.3.png%3Fraw%3Dtrue" alt="firebase2.3.png" width="800" height="412"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="k"&gt;buildscript&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;buildToolsVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"28.0.3"&lt;/span&gt;
        &lt;span class="n"&gt;minSdkVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;
        &lt;span class="n"&gt;compileSdkVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;
        &lt;span class="n"&gt;targetSdkVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;
        &lt;span class="n"&gt;googlePlayServicesAuthVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"18.0.0"&lt;/span&gt; &lt;span class="c1"&gt;// Add this line&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;jcenter&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;classpath&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"com.android.tools.build:gradle:3.4.2"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;classpath&lt;/span&gt; &lt;span class="s1"&gt;'com.google.gms:google-services:4.3.3'&lt;/span&gt; &lt;span class="c1"&gt;// Add this line&lt;/span&gt;
        &lt;span class="c1"&gt;// NOTE: Do not place your application dependencies here; they belong&lt;/span&gt;
        &lt;span class="c1"&gt;// in the individual module build.gradle files&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Add Google Play Services plugin in App-level build.gradle (android/appp/build.gradle):
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="nl"&gt;plugin:&lt;/span&gt; &lt;span class="s1"&gt;'com.google.gms.google-services'&lt;/span&gt; &lt;span class="c1"&gt;// Add at end of the file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  e.g.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KowNMv3T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.4.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KowNMv3T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.4.png%3Fraw%3Dtrue" alt="firebase2.4.png" width="800" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In firebase, you will need to enable Google option in SignIn Method section&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8-BkJ1DP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.5.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8-BkJ1DP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.5.png%3Fraw%3Dtrue" alt="firebase2.5.png" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While enabling Google, do copy the &lt;code&gt;Web Client ID&lt;/code&gt; from there, we need this later on. 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xFT3ugn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/anwargul0x/HookOn/blob/Host_Images/HostAssets/firebase2.6.png%3Fraw%3Dtrue" alt="firebase2.6.png" width="508" height="513"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Let's get our hands dirty with the code
&lt;/h1&gt;

&lt;p&gt;I will be making a simple app of just two components to App.js (already exists by default) and second will be Home.js.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import Public Api of &lt;code&gt;@react-native-community/google-signin&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;GoogleSigninButton&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;statusCodes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-native-community/google-signin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;But before you can use above imports you need  call once, configure of GoogleSignin. You can call it in &lt;strong&gt;ComponentDidMount&lt;/strong&gt; life Cycle method
or you can use &lt;strong&gt;useEffect&lt;/strong&gt; Hook
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
 &lt;span class="na"&gt;webClientId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;WebClientID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// client ID of type WEB for your server(needed to verify user ID and offline access)&lt;/span&gt;
 &lt;span class="na"&gt;offlineAccess&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// if you want to access Google API on behalf of the user FROM YOUR SERVER&lt;/span&gt;
 &lt;span class="na"&gt;forceCodeForRefreshToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// [Android] related to `serverAuthCode`, read the docs link below *.&lt;/span&gt;
 &lt;span class="na"&gt;accountName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// [Android] specifies an account name on the device that should be used&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Sign in function
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
 &lt;span class="nx"&gt;signIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasPlayServices&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signIn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;userInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nx"&gt;setUserInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;statusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SIGN_IN_CANCELLED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// user cancelled the login flow&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;statusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;IN_PROGRESS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// operation (e.g. sign in) is in progress already&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;statusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PLAY_SERVICES_NOT_AVAILABLE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// play services not available or outdated&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// some other error happened&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Sign out function
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;signOut&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;revokeAccess&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;GoogleSignin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signOut&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nx"&gt;setUserInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Remember to remove the user from your app's state as well&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Demo App Preview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0PJeGzfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://s4.gifyu.com/images/ezgif.com-optimize00986b78df17d105.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0PJeGzfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://s4.gifyu.com/images/ezgif.com-optimize00986b78df17d105.gif" alt="ezgif.com-optimize00986b78df17d105.gif" width="278" height="620"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Do check the official Docs and if you have any questions let me know.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/react-native-google-signin"&gt;
        react-native-google-signin
      &lt;/a&gt; / &lt;a href="https://github.com/react-native-google-signin/google-signin"&gt;
        google-signin
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Google Sign-in for your React Native applications
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/react-native-google-signin/google-signinimg/header.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2O0ab2-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/react-native-google-signin/google-signinimg/header.png" alt="React Native Google Sign In"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://www.npmjs.com/package/@react-native-google-signin/google-signin" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/e02ae743c01d041fccd2a5674672f24f5663787a131882a38514e2dbc912f480/68747470733a2f2f62616467652e667572792e696f2f6a732f4072656163742d6e61746976652d676f6f676c652d7369676e696e253246676f6f676c652d7369676e696e2e737667" alt="NPM Version"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;
🚧🚧 New features planned: looking for financial backers and collaborators 🚧🚧
&lt;/h3&gt;
&lt;p&gt;See this &lt;a href="https://github.com/react-native-google-signin/google-signin/issues/942"&gt;issue&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Support all 3 types of authentication methods (standard, with server-side validation or with offline access (aka server-side access))&lt;/li&gt;
&lt;li&gt;Promise-based API consistent between Android and iOS&lt;/li&gt;
&lt;li&gt;Typings for TypeScript and Flow&lt;/li&gt;
&lt;li&gt;Mock of the native module for testing with Jest&lt;/li&gt;
&lt;li&gt;Native sign in buttons&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Requirements&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;RN &amp;gt;= 0.60&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Project setup and initialization&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;yarn add @react-native-google-signin/google-signin&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Then follow the &lt;a href="https://github.com/react-native-google-signin/google-signindocs/android-guide.md"&gt;Android guide&lt;/a&gt; and &lt;a href="https://github.com/react-native-google-signin/google-signindocs/ios-guide.md"&gt;iOS guide&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Expo installation&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;This package cannot be used in the "Expo Go" app because &lt;a href="https://docs.expo.io/workflow/customizing/" rel="nofollow"&gt;it requires custom native code&lt;/a&gt;. &lt;em&gt;However, you can add custom native code to expo by following the guide below.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npx expo install @react-native-google-signin/google-signin&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After installing this npm package, add the &lt;a href="https://docs.expo.io/guides/config-plugins/" rel="nofollow"&gt;config plugin&lt;/a&gt; to the &lt;a href="https://docs.expo.io/versions/latest/config/app/#plugins" rel="nofollow"&gt;&lt;code&gt;plugins&lt;/code&gt;&lt;/a&gt; array of your &lt;code&gt;app.json&lt;/code&gt; or &lt;code&gt;app.config.js&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight highlight-source-json notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;{
  &lt;span class="pl-ent"&gt;"expo"&lt;/span&gt;: {
    &lt;span class="pl-ent"&gt;"android"&lt;/span&gt;: {
      &lt;span class="pl-ent"&gt;"googleServicesFile"&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;"&lt;/span&gt;./google-services.json&lt;span class="pl-pds"&gt;"&lt;/span&gt;&lt;/span&gt;
    }
    &lt;span class="pl-ent"&gt;"ios"&lt;/span&gt;:&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/react-native-google-signin/google-signin"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;I hope you like this post and I will be posting more post soon and most importantly All suggestions are welcome. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vmrn3lfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/960/0%2A0mc4QYmX3rCaQCh9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vmrn3lfA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/960/0%2A0mc4QYmX3rCaQCh9" alt="See Ya" width="480" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>android</category>
      <category>javascript</category>
      <category>googlesignin</category>
    </item>
    <item>
      <title>Javascript ES6 Declarations Guide.</title>
      <dc:creator>Anwar Gul</dc:creator>
      <pubDate>Sun, 01 Mar 2020 03:27:43 +0000</pubDate>
      <link>https://dev.to/anwargul0x/javascript-es6-declarations-guide-44a2</link>
      <guid>https://dev.to/anwargul0x/javascript-es6-declarations-guide-44a2</guid>
      <description>&lt;p&gt;In this article, we will be discussing the very fundamental and the basic building block in your javascript programming journey i.e Variables. In JavaScript, there are three keywords used to declare a variable &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; and each one affects how the code will interpret the variable differently.&lt;/p&gt;

&lt;h2&gt;
  
  
  NOTE: &lt;em&gt;JavaScript-only hoist declarations, not initializations. So all declarations are hoisted.&lt;/em&gt;
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@anwargul0x/javascript-es6-declarations-the-complete-guide-485d51039dd1" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fv2%2Fresize%3Afill%3A88%3A88%2F1%2AvftJmOLH3-mHpHUw_k4AnA.png" alt="Anwar Gul"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@anwargul0x/javascript-es6-declarations-the-complete-guide-485d51039dd1" class="ltag__link__link" rel="noopener noreferrer"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Javascript ES6 Declarations Guide. | by Anwar Gul | The Startup | Medium&lt;/h2&gt;
      &lt;h3&gt;Anwar Gul ・ &lt;time&gt;Sep 6, 2020&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&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%2Fassets%2Fmedium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h1&gt;
  
  
  &lt;strong&gt;1- VAR&lt;/strong&gt;
&lt;/h1&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%2Fmiro.medium.com%2Fmax%2F629%2F1%2AUPhhGL64zVo92ywNdWdd9w.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%2Fmiro.medium.com%2Fmax%2F629%2F1%2AUPhhGL64zVo92ywNdWdd9w.png" alt="Declaration Syntax with Var Keyword"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This statement consists of a few parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The declaration of a variable using the &lt;code&gt;var&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;The variable name (or identifier), author&lt;/li&gt;
&lt;li&gt;The assignment operation, represented by the = syntax&lt;/li&gt;
&lt;li&gt;The value being assigned, "Anwar"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Declarations with &lt;code&gt;var&lt;/code&gt; keyword can either be of global scope or function scope depending on the current execution context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Current Execution Context&lt;/strong&gt;: &lt;em&gt;Declaration inside function is in the function scope/local scope. Outside of the function, any declaration is in the global scope.&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%2Fmiro.medium.com%2Fmax%2F874%2F1%2Ai6N2M7IgKH5CeKcf7CITKw.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%2Fmiro.medium.com%2Fmax%2F874%2F1%2Ai6N2M7IgKH5CeKcf7CITKw.png" alt="Variable Declaration with the var keyword."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As above can be seen the declared variables are initialized with “undefined” by default. Hence var variables can be declared without being initialized.&lt;br&gt;
&lt;code&gt;var&lt;/code&gt; variables can be reassigned and/or redeclared within its scope. For Instance :&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%2Fmiro.medium.com%2Fmax%2F1728%2F1%2AkpdcExbblTzklBteYwbhMQ.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%2Fmiro.medium.com%2Fmax%2F1728%2F1%2AkpdcExbblTzklBteYwbhMQ.png" alt="Reassigned and Redeclared variable in Global Scope"&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%2Fmiro.medium.com%2Fmax%2F1762%2F1%2AK3owua2XHj77MF1ZQWSEkg.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%2Fmiro.medium.com%2Fmax%2F1762%2F1%2AK3owua2XHj77MF1ZQWSEkg.png" alt="Reassigned and Redeclared variable in Function Scope"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Declarations with var keyword are hoisted to the top of their scope.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;2- Let&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Declarations with &lt;code&gt;let&lt;/code&gt; keyword are &lt;em&gt;Block scoped&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Scope&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%2Fmiro.medium.com%2Fmax%2F797%2F1%2Awyp9Pm_553BKzJ-eEba9ZQ.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%2Fmiro.medium.com%2Fmax%2F797%2F1%2Awyp9Pm_553BKzJ-eEba9ZQ.png" alt="Block Scope"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In layman’s term the definition of Block Scope, &lt;em&gt;“A boundary that starts from an opening curly brace { and ends on closing curly brace } while optionally enclosing some amount of code.”&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%2Fmiro.medium.com%2Fmax%2F1024%2F1%2AFB_E4wY1RJafVdg_AEKLuw.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%2Fmiro.medium.com%2Fmax%2F1024%2F1%2AFB_E4wY1RJafVdg_AEKLuw.png" alt="Example of Temporal Dead Zone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Variables with &lt;code&gt;let&lt;/code&gt; are &lt;strong&gt;hoisted&lt;/strong&gt;. But by looking at the above example it seems let variables aren't hoisted but the matter of fact this happens due to concept &lt;strong&gt;Temporal Dead Zone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;since &lt;code&gt;let&lt;/code&gt; variables are not initialized until the javascript engine evaluates the assignment. A time from variable creation to its initialization where they can’t be accessed is known as &lt;strong&gt;Temporal Dead Zone&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the JavaScript engine can’t find the value of &lt;code&gt;let&lt;/code&gt; variables at the line where they were declared, it will assign them the value of &lt;em&gt;undefined&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%2Fmiro.medium.com%2Fmax%2F990%2F1%2AM3LOgCAeEoBNufCM57ZxQg.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%2Fmiro.medium.com%2Fmax%2F990%2F1%2AM3LOgCAeEoBNufCM57ZxQg.png" alt="Reassignment is allowed but Redeclaration is not."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Variables with &lt;code&gt;let&lt;/code&gt; declaration can be updated/re-assigned but they can’t be redeclared.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;3- Const&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Just like &lt;code&gt;let&lt;/code&gt;, Declarations with &lt;code&gt;const&lt;/code&gt; keyword are also &lt;strong&gt;Block scoped&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; variables are also hoisted. If the JavaScript engine can’t find the value of &lt;code&gt;const&lt;/code&gt; variables at the line where they were declared, return an 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%2Fmiro.medium.com%2Fmax%2F730%2F1%2AiKA3J5BcsTIws_1mIkIM9A.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%2Fmiro.medium.com%2Fmax%2F730%2F1%2AiKA3J5BcsTIws_1mIkIM9A.png" alt="const variables can not be declared without assigning a value."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; variables can not be declared without assigning a value.&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%2Fmiro.medium.com%2Fmax%2F831%2F1%2A7xefkQlbrrlTnZC0z3_uyw.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%2Fmiro.medium.com%2Fmax%2F831%2F1%2A7xefkQlbrrlTnZC0z3_uyw.png" alt="So const variables can’t be updated/reassigned a new value"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;const&lt;/code&gt; variables can’t be updated/reassigned a new value&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%2Fmiro.medium.com%2Fmax%2F990%2F1%2A2LpR-8kGuYu6JXtSzJQBkg.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%2Fmiro.medium.com%2Fmax%2F990%2F1%2A2LpR-8kGuYu6JXtSzJQBkg.png" alt="And also const variables can’t be redeclared"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And also &lt;code&gt;const&lt;/code&gt; variables can’t be redeclared.&lt;/p&gt;

&lt;h2&gt;
  
  
  BONUS
&lt;/h2&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%2Fmiro.medium.com%2Fmax%2F498%2F1%2AQG3qPCDNo2gKVN5fDC3dkQ.gif" 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%2Fmiro.medium.com%2Fmax%2F498%2F1%2AQG3qPCDNo2gKVN5fDC3dkQ.gif" alt="thinking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are thinking about something like “Hey Anwar, I got all that but you never answered! what would happen if we don’t use any of the keywords that you mentioned”.&lt;/p&gt;

&lt;p&gt;Well, I will be keeping it brief since it already been become a lengthy post.&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%2Fmiro.medium.com%2Fmax%2F1746%2F1%2AXIDTZXOgTXqzE8DPeDjjKw.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%2Fmiro.medium.com%2Fmax%2F1746%2F1%2AXIDTZXOgTXqzE8DPeDjjKw.png" alt="Variables without declarations."&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;variables without declaration become a part of the &lt;strong&gt;global variable&lt;/strong&gt;, in the console that would be &lt;code&gt;window&lt;/code&gt; and in node.js &lt;code&gt;global&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SUMMARY
&lt;/h2&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%2Fmiro.medium.com%2Fmax%2F1024%2F1%2A6xNL-BrNy2QjAZ2oz8r2vA.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%2Fmiro.medium.com%2Fmax%2F1024%2F1%2A6xNL-BrNy2QjAZ2oz8r2vA.png" alt="Summary."&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I hope you like this article and I will be posting more articles soon and most importantly All suggestions are welcome.&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%2Fmiro.medium.com%2Fmax%2F480%2F0%2A0mc4QYmX3rCaQCh9" 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%2Fmiro.medium.com%2Fmax%2F480%2F0%2A0mc4QYmX3rCaQCh9" alt="See you soon!."&gt;&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>declarations</category>
      <category>es6</category>
    </item>
  </channel>
</rss>
