<?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: Abhishek singh </title>
    <description>The latest articles on DEV Community by Abhishek singh  (@abhisheksrajput).</description>
    <link>https://dev.to/abhisheksrajput</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%2F693430%2Fe89e7205-f13b-4924-9cf7-c97e091967a2.jpg</url>
      <title>DEV Community: Abhishek singh </title>
      <link>https://dev.to/abhisheksrajput</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhisheksrajput"/>
    <language>en</language>
    <item>
      <title>HTML Interview Preparation Topics</title>
      <dc:creator>Abhishek singh </dc:creator>
      <pubDate>Sun, 20 Oct 2024 20:04:27 +0000</pubDate>
      <link>https://dev.to/abhisheksrajput/html-interview-preparation-topics-5hei</link>
      <guid>https://dev.to/abhisheksrajput/html-interview-preparation-topics-5hei</guid>
      <description>&lt;h2&gt;
  
  
  1. What is HTML?
&lt;/h2&gt;

&lt;p&gt;HTML stands for &lt;strong&gt;Hypertext Markup Language&lt;/strong&gt;, used to create web pages and provide structure to the content on the web.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt;: Defines the document as an HTML5 document.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;: The root element wrapping all content.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;: Contains meta-information like character encoding, viewport settings, and page title.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;: Sets the title of the webpage.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;: Contains the visible content of the webpage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Difference Between Tag and Element?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tags&lt;/strong&gt; are enclosed within angle brackets (&lt;code&gt;&amp;lt; &amp;gt;&lt;/code&gt;). For example, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; is a start tag for a paragraph, and &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; is an end tag.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Element&lt;/strong&gt;: Includes both the start tag, content (if any), and the end tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Types of Lists
&lt;/h2&gt;

&lt;p&gt;There are three types of lists in HTML:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ordered List&lt;/strong&gt; (&lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unordered List&lt;/strong&gt; (&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description List&lt;/strong&gt; (&lt;code&gt;&amp;lt;dl&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dl&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;dt&amp;gt;&lt;/span&gt;HTML&lt;span class="nt"&gt;&amp;lt;/dt&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!--description term--&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;dd&amp;gt;&lt;/span&gt;HyperText Markup Language&lt;span class="nt"&gt;&amp;lt;/dd&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!--description definition--&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;dt&amp;gt;&lt;/span&gt;CSS&lt;span class="nt"&gt;&amp;lt;/dt&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;dd&amp;gt;&lt;/span&gt;Cascading Style Sheets&lt;span class="nt"&gt;&amp;lt;/dd&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dl&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Basic Structure of Tables
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Header 1&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Header 2&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;Row 1, Cell 1&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;Row 1, Cell 2&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Difference Between Link and Anchor?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; (anchor)&lt;/strong&gt;: Creates hyperlinks to other pages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;href&lt;/code&gt;: Specifies the URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;target&lt;/code&gt;: Specifies where to open the link (e.g., new tab).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;download&lt;/code&gt;: Allows file download.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Defines relationships between the current document and external resources (e.g., stylesheets).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rel&lt;/code&gt;: Specifies the relationship (e.g., &lt;code&gt;stylesheet&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;href&lt;/code&gt;: Specifies the URL of the external resource.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. What are Attributes?
&lt;/h2&gt;

&lt;p&gt;Attributes provide additional information about HTML elements and are written in the opening tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Difference Between Inline and Block Elements?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block Level Element&lt;/strong&gt;: Takes up the full width available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inline Element&lt;/strong&gt;: Takes only the necessary width.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Forms
&lt;/h2&gt;

&lt;p&gt;HTML forms allow users to submit data. Forms typically include input elements like text fields, checkboxes, radio buttons, and submit buttons.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;: Contains action URL and method (GET/POST).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;: Fields for user data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;: Associates text with input elements.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;: Triggers form submission.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt; element is a &lt;strong&gt;semantic tag&lt;/strong&gt; used to represent self-contained and independent content, introduced in HTML5.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; element is used for content related to the main content but separate from it (e.g., sidebars).&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Audio and Video
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;audio&lt;/span&gt; &lt;span class="na"&gt;controls&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;source&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"audio.mp3"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"audio/mpeg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/audio&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;video&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"320"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"240"&lt;/span&gt; &lt;span class="na"&gt;controls&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;source&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"video.mp4"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"video/mp4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/video&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  12. &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; element allows for dynamic, scriptable rendering of 2D and 3D graphics.&lt;/p&gt;

&lt;h2&gt;
  
  
  13. Semantic HTML
&lt;/h2&gt;

&lt;p&gt;Focuses on using tags that describe the meaning of the content, making web pages more accessible and SEO-friendly.&lt;/p&gt;

&lt;h2&gt;
  
  
  14. Accessibility
&lt;/h2&gt;

&lt;p&gt;Ensures people with disabilities can navigate your website by using semantic tags, &lt;code&gt;alt&lt;/code&gt; text for images, and proper form labeling.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. Best Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use proper indentation for readability.&lt;/li&gt;
&lt;li&gt;Write meaningful content, like &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; and &lt;code&gt;alt&lt;/code&gt; attributes.&lt;/li&gt;
&lt;li&gt;Ensure valid HTML by using &lt;a href="https://validator.w3.org/" rel="noopener noreferrer"&gt;W3C Markup Validation Service&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  16. CSS Performance Optimization Techniques
&lt;/h2&gt;

&lt;p&gt;When a browser loads a page, it pauses HTML parsing to fetch and apply CSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Concepts:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CSS is render-blocking by default, meaning the browser won't render the page until all CSS is loaded.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Optimization Techniques:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Critical CSS&lt;/strong&gt;: Inline the minimum CSS needed for above-the-fold content.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;CSS Media Attributes&lt;/strong&gt;: Load CSS conditionally based on device characteristics.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt; &lt;span class="na"&gt;media=&lt;/span&gt;&lt;span class="s"&gt;"screen and (min-width: 600px)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Defer Non-Critical CSS&lt;/strong&gt;: Load non-essential CSS asynchronously.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preload"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt; &lt;span class="na"&gt;as=&lt;/span&gt;&lt;span class="s"&gt;"style"&lt;/span&gt; &lt;span class="na"&gt;onload=&lt;/span&gt;&lt;span class="s"&gt;"this.rel='stylesheet'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Minify CSS&lt;/strong&gt;: Remove unnecessary spaces and comments to reduce file size using tools like CSS-Nano.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  17. Loading and Parsing JavaScript
&lt;/h2&gt;

&lt;p&gt;JavaScript can significantly impact page load times, so optimizing how you load and execute JS is crucial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Concepts:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript is &lt;strong&gt;render-blocking&lt;/strong&gt; by default.&lt;/li&gt;
&lt;li&gt;Scripts are parsed and executed in the order they appear.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Optimization Techniques:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Defer and Async Attributes&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;defer&lt;/code&gt;: Downloads scripts during HTML parsing but executes them after the document is parsed.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;async&lt;/code&gt;: Downloads and executes scripts as soon as they're available (order not guaranteed).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt; &lt;span class="na"&gt;async&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Place scripts at the end of &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Ensures HTML is parsed before JavaScript executes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minify and Bundle JS&lt;/strong&gt;: Use tools like UglifyJS or Terser to reduce file size and improve performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  18. Preloading vs Prefetching
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Preload&lt;/strong&gt;: Loads critical assets early.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preload"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"critical-styles.css"&lt;/span&gt; &lt;span class="na"&gt;as=&lt;/span&gt;&lt;span class="s"&gt;"style"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prefetch&lt;/strong&gt;: Downloads resources for future navigation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"prefetch"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"next-page.html"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  19. Lazy Loading
&lt;/h2&gt;

&lt;p&gt;Delays loading of certain resources until they are needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Load Images&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"image.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Image"&lt;/span&gt; &lt;span class="na"&gt;loading=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Load JavaScript&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;load-script&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&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;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./heavy-script.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Use the module&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;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;To optimize CSS and JavaScript loading and parsing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inline critical CSS and defer non-essential styles.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;defer&lt;/code&gt; or &lt;code&gt;async&lt;/code&gt; to prevent render-blocking JS.&lt;/li&gt;
&lt;li&gt;Minify and bundle CSS and JavaScript for better performance.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Can you solve these Javascript Mind Twister Puzzles by ChatGPT? 🤯</title>
      <dc:creator>Abhishek singh </dc:creator>
      <pubDate>Fri, 05 May 2023 17:41:07 +0000</pubDate>
      <link>https://dev.to/abhisheksrajput/can-you-solve-these-javascript-mind-twister-puzzles-by-chatgpt-58cf</link>
      <guid>https://dev.to/abhisheksrajput/can-you-solve-these-javascript-mind-twister-puzzles-by-chatgpt-58cf</guid>
      <description>&lt;p&gt;I had a fascinating experience when I reached out to ChatGPT for mind twister puzzles. As someone who enjoys a good mental challenge, I was thoroughly intrigued by the puzzles that were presented to me. Some of the puzzles were particularly perplexing and left me feeling utterly confused, but this only served to make the experience more thrilling. Overall, I was grateful for the opportunity to exercise my cognitive abilities and engage in a mentally stimulating activity.&lt;/p&gt;

&lt;p&gt;I have organized the puzzles, complete with answers and explanations for each one. With a link at the end of every &lt;code&gt;Question&lt;/code&gt; and &lt;code&gt;Answer&lt;/code&gt;, readers can easily navigate. I hope that this blog post will be a valuable resource for those who enjoy mental challenges and provide a good read.&lt;/p&gt;

&lt;p&gt;📢 Let's begin...&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;1. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: console.log(1 + "2" + "2");
b: console.log(1 + +"2" + "2");
c: console.log(1 + -"1" + "2");
d: console.log(+"1" + "1" + "2");
e: console.log("A" - "B" + "2");
f: console.log("A" - "B" + 2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Answer a - Answer b
&lt;/li&gt;
&lt;li&gt;
Answer c - Answer d
&lt;/li&gt;
&lt;li&gt;
Answer e - Answer f
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;2. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 5; i++) {
  setTimeout(() =&amp;gt; console.log(i), 100);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;3. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = {b: 1};
const b = {c: 2};
const c = {...a, ...b};
console.log(c);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;4. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = [1, 2, 3];
const b = [1, 2, 3];
const c = "1,2,3";
console.log(a == c);
console.log(b == c);
console.log(a == b);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;5. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function a (){
  return arguments;
} 
console.log(a(1, 2, 3));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;6. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = [1, 2, 3];
a[10] = 10;
a: console.log(a);
b: console.log(a.length);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;7. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = [1, 2, 3];
a[-1] = 0;
console.log(a);
console.log(a.length);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;8. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = {a: 1, b: 2};
const b = {b: 3, c: 4};
const c = {...a, ...b};
console.log(c);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;9. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(typeof NaN);
console.log(NaN == NaN);
console.log(NaN === NaN);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;&lt;/a&gt;10. What is the output of the following code snippet?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = "hello";
a.toUpperCase();
console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📄🫡&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer&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%2Fuploads%2Farticles%2F72dl1hz0uw8sjtkd6fnw.jpg" 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%2Fuploads%2Farticles%2F72dl1hz0uw8sjtkd6fnw.jpg" alt="goat with wrong answers" width="640" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Answers:-
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Note&lt;/strong&gt; `In JavaScript, the + operator is used for both addition and string concatenation. When you use the + operator with a number and a string, JavaScript converts the number to a string and then concatenates the two strings together.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Answer 1 a
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In the expression 1 + "2" + "2", the first + operator is between a number (1) and a string ("2"), so JavaScript converts the number to a string and concatenates it with the string "2". The result of this operation is the string "12".&lt;/li&gt;
&lt;li&gt;The second + operator is between two strings ("12" and "2"), so JavaScript simply concatenates them together, resulting in the string "122".&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log(1 + "2" + "2"); would be &lt;strong&gt;"122"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 1 b
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In the expression +"2", the + operator is used as a unary operator on the string "2". Since the string "2" can be converted to a number, the result of this operation is the number 2.&lt;/li&gt;
&lt;li&gt;Therefore, the expression 1 + +"2" + "2" can be rewritten as 1 + 2 + "2".&lt;/li&gt;
&lt;li&gt;The first + operator is between a number (1) and a number (2), so JavaScript adds them together, resulting in the number 3.&lt;/li&gt;
&lt;li&gt;The second + operator is between a number (3) and a string ("2"), so JavaScript converts the number 3 to a string and concatenates it with the string "2". The result of this operation is the string "32".&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log(1 + +"2" + "2"); would be &lt;strong&gt;"32"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 1 c
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In the expression - "1", the - operator is used as a unary operator on the string "1". Since the string "1" can be converted to a number, the result of this operation is the number -1.&lt;/li&gt;
&lt;li&gt;Therefore, the expression 1 + -"1" + "2" can be rewritten as 1 + (-1) + "2".&lt;/li&gt;
&lt;li&gt;The first + operator is between a number (1) and a number (-1), so JavaScript adds them together, resulting in the number 0.&lt;/li&gt;
&lt;li&gt;The second + operator is between a number (0) and a string ("2"), so JavaScript converts the number 0 to a string and concatenates it with the string "2". The result of this operation is the string "02".&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log(1 + -"1" + "2"); would be &lt;strong&gt;"02"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 1 d
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In the expression +"1", the + operator is used as a unary operator on the string "1". Since the string "1" can be converted to a number, the result of this operation is the number 1.&lt;/li&gt;
&lt;li&gt;Therefore, the expression +"1" + "1" + "2" can be rewritten as 1 + "1" + "2".&lt;/li&gt;
&lt;li&gt;The first + operator is between a number (1) and a string ("1"), so JavaScript converts the number 1 to a string and concatenates it with the string "1". The result of this operation is the string "11".&lt;/li&gt;
&lt;li&gt;The second + operator is between a string ("11") and a string ("2"), so JavaScript concatenates them together, resulting in the string "112".&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log(+"1" + "1" + "2"); would be &lt;strong&gt;"112"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 1 e
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In JavaScript, the - operator is used for subtraction between two numbers. When you use the - operator with a string, JavaScript tries to convert the string to a number.&lt;/li&gt;
&lt;li&gt;In the expression "A" - "B", JavaScript tries to subtract the numbers represented by the strings "A" and "B". However, since these strings cannot be converted to numbers, the result of this operation is NaN (Not a Number).&lt;/li&gt;
&lt;li&gt;Therefore, the expression "A" - "B" + "2" can be rewritten as NaN + "2".&lt;/li&gt;
&lt;li&gt;The + operator is between NaN and a string ("2"), so JavaScript converts NaN to the string "NaN" and concatenates it with the string "2". The result of this operation is the string "NaN2".&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log("A" - "B" + "2"); would be &lt;strong&gt;"NaN2"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 1 f
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In the expression "A" - "B", JavaScript tries to subtract the numbers represented by the strings "A" and "B". However, since these strings cannot be converted to numbers, the result of this operation is NaN (Not a Number).&lt;/li&gt;
&lt;li&gt;Therefore, the expression "A" - "B" + 2 can be rewritten as NaN + 2.&lt;/li&gt;
&lt;li&gt;The + operator is between NaN and a number (2). Any arithmetic operation involving NaN will result in NaN.&lt;/li&gt;
&lt;li&gt;Therefore, the output of the code console.log("A" - "B" + 2); would be &lt;strong&gt;NaN&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 1&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 2
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;This code block creates a for loop that iterates over i from 0 to 4. For each iteration of the loop, it schedules a function call to console.log(i) using the setTimeout method with a delay of 100 milliseconds.&lt;/li&gt;
&lt;li&gt;The setTimeout method is used to execute a function after a specified delay. In this case, the function is an arrow function that logs the value of i to the console.&lt;/li&gt;
&lt;li&gt;However, because of the asynchronous nature of the setTimeout method, the function calls are not executed immediately, and the loop continues to run before the scheduled function calls are executed.&lt;/li&gt;
&lt;li&gt;When the scheduled function calls are eventually executed, they will use the value of i that exists at the time of execution. At this point, the for loop has already completed and the value of i is equal to &lt;strong&gt;5&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;As a result, the output of this code block will be five &lt;strong&gt;5&lt;/strong&gt; logged to the console with a delay of 100 milliseconds between each log statement.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 2&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 3
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;This code block creates three objects: a, b, and c. &lt;code&gt;a&lt;/code&gt; has a property b with a value of 1, and b has a property c with a value of 2.&lt;/li&gt;
&lt;li&gt;The "..." operator is the spread operator, which is used to expand the properties of an object into another object or an array. In this code block, the spread operator is used to create a new object c that combines the properties of a and b.&lt;/li&gt;
&lt;li&gt;The spread operator in const c = {...a, ...b}; first spreads the properties of a into c, and then spreads the properties of b into c. Since there are no common property names between a and b, the properties are simply added to c.&lt;/li&gt;
&lt;li&gt;Therefore, the value of c will be an object with two properties: b with a value of 1 and c with a value of 2.&lt;/li&gt;
&lt;li&gt;The output of console.log(c); will be &lt;strong&gt;{b: 1, c: 2}&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 3&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 4
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In JavaScript, when using the equality operator (==) to compare two values, if the operands are of different types, JavaScript tries to convert one or both of the operands to a common type before making the comparison.&lt;/li&gt;
&lt;li&gt;In this code block, a and b are both arrays containing the same values [1, 2, 3]. c is a string that contains the same values as a and b, separated by commas.&lt;/li&gt;
&lt;li&gt;When a == c is evaluated, JavaScript tries to convert c to an array. Since c is a string, it is converted to an array with one element, which is the string "1,2,3". This is not equal to a, which is an array with three elements, so the expression evaluates to false.&lt;/li&gt;
&lt;li&gt;Similarly, when b == c is evaluated, JavaScript tries to convert c to an array. Again, c is converted to an array with one element, which is the string "1,2,3". This is not equal to b, which is an array with three elements, so the expression evaluates to false.&lt;/li&gt;
&lt;li&gt;However, when a == b is evaluated, both operands are arrays of the same type, so JavaScript compares the values of the arrays. Even though a and b contain the same values, they are different arrays in memory, so the expression evaluates to false.&lt;/li&gt;
&lt;li&gt;Therefore, the output of console.log(a == c); and console.log(b == c); will be false, and the output of console.log(a == b); will also be false.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 4&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 5
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In this code block, &lt;code&gt;a&lt;/code&gt; is a function that returns the arguments object. The arguments object is a built-in object in JavaScript that is available inside functions and contains an array-like list of the arguments passed to the function.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;a&lt;/code&gt; is called with the arguments 1, 2, and 3 (a(1, 2, 3)), it returns the arguments object that contains an array-like list of the arguments passed to the function. In this case, the arguments object will contain three elements: 1, 2, and 3.&lt;/li&gt;
&lt;li&gt;The output of console.log(a(1, 2, 3)); will be the arguments object, which looks like an array but is not an actual array. Depending on the environment, the output may look something like this:
&lt;code&gt;
Arguments [ 1, 2, 3 ]
&lt;/code&gt;
Or
&lt;code&gt;
Arguments { '0': 1, '1': 2, '2': 3 }
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In general, it's not recommended to use the arguments object in modern JavaScript code because it can make code harder to read and maintain. Instead, it's better to use the rest parameter syntax (...args) to capture a variable number of arguments as an actual array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 5&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 6
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In this code block, &lt;code&gt;a&lt;/code&gt; is an array with three elements [1, 2, 3]. However, when a[10] = 10 is executed, a new element is added to the array at index 10, with the value 10. This means that the array a now has a length of 11, and the elements at indices 3 through 9 are undefined.&lt;/li&gt;
&lt;li&gt;When console.log(a) is called, the output will be the array a, which looks something like this:
&lt;code&gt;
[1, 2, 3, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 10]
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When console.log(a.length) is called, the output will be the length of the array a, which is 11. Even though only four elements have been explicitly defined in the array (a[0], a[1], a[2], and a[10]), JavaScript automatically assigns a length to the array based on the highest index that has been assigned a value plus one. In this case, the highest index assigned a value is &lt;strong&gt;10&lt;/strong&gt;, so the length of the array is &lt;strong&gt;11&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 6&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 7
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In this code block, &lt;code&gt;a&lt;/code&gt; is an array with three elements [1, 2, 3]. However, when a[-1] = 0 is executed, a new element is added to the array at index -1, with the value 0. This might seem unusual, but in JavaScript, array indices are actually just object property names, and any property name can be used, including negative numbers. However, using negative indices can make code harder to read and understand, so it's generally not recommended.&lt;/li&gt;
&lt;li&gt;When console.log(a) is called, the output will be the array a, which looks something like this:
&lt;code&gt;
[1, 2, 3, '-1': 0]
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Notice that the element at index -1 is included in the output as a property with the name '-1'.&lt;/li&gt;
&lt;li&gt;When console.log(a.length) is called, the output will be the length of the array &lt;code&gt;a&lt;/code&gt;, which is 3. This is because the length property of an array in JavaScript always returns one more than the highest index in the array. In this case, the highest index is 2, so the length of the array is 3. The fact that there is a property with the name '-1' does not affect the length of the array, since the length property only considers elements with non-negative integer indices.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 7&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 8
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In this code block, &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are two objects with properties &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt;, 4 respectively. When &lt;code&gt;c&lt;/code&gt; is assigned the result of the spread operation {...a, ...b}, it creates a new object &lt;code&gt;c&lt;/code&gt; by combining the properties of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; using the spread operator.&lt;/li&gt;
&lt;li&gt;The resulting object &lt;code&gt;c&lt;/code&gt; will have the properties of both &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, and any properties with the same name will be overwritten by the value of the property from &lt;code&gt;b&lt;/code&gt;. In this case, since both &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; have a property named &lt;code&gt;b&lt;/code&gt;, the value of &lt;code&gt;b&lt;/code&gt; in the resulting object &lt;code&gt;c&lt;/code&gt; will be 3 (from b). Similarly, &lt;code&gt;c&lt;/code&gt; will have properties &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, and &lt;code&gt;c&lt;/code&gt;, with values 1, 3, and 4, respectively.&lt;/li&gt;
&lt;li&gt;When console.log(c) is called, the output will be the object c, which looks something like this:
&lt;code&gt;
{a: 1, b: 3, c: 4}
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Notice that the &lt;code&gt;b&lt;/code&gt; property in &lt;code&gt;c&lt;/code&gt; has the value 3, which was taken from &lt;code&gt;b&lt;/code&gt; and overwritten the value of &lt;code&gt;b&lt;/code&gt; in &lt;code&gt;a&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 8&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 9
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;The NaN (Not a Number) value in JavaScript is a special value that represents the result of an undefined or unrepresentable mathematical operation, such as dividing zero by zero, or multiplying infinity by zero. NaN is a numeric value, but it is not equal to any other value, including itself.&lt;/li&gt;
&lt;li&gt;When console.log(typeof NaN) is called, the output will be number. This is because NaN is considered a special numeric value in JavaScript.&lt;/li&gt;
&lt;li&gt;When console.log(NaN == NaN) is called, the output will be false. This is because NaN is not equal to any value, including itself. Even though NaN is a numeric value, it is not considered equal to any other numeric value or NaN itself.&lt;/li&gt;
&lt;li&gt;When console.log(NaN === NaN) is called, the output will also be false. This is because the === operator tests for both equality of value and type, and since both NaN values are of the same type (number), the result is still false.&lt;/li&gt;
&lt;li&gt;Therefore, it is important to be careful when working with &lt;code&gt;NaN&lt;/code&gt; in JavaScript and to check for NaN values explicitly, such as by using the &lt;code&gt;isNaN()&lt;/code&gt; function or the &lt;code&gt;Number.isNaN()&lt;/code&gt; method.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 9&lt;/p&gt;

&lt;h5&gt;
  
  
  Answer 10
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In this code block, &lt;code&gt;a&lt;/code&gt; is a constant string variable containing the value "hello". When the toUpperCase() method is called on &lt;code&gt;a&lt;/code&gt;, it returns a new string with all characters in uppercase, but it does not modify the original string a itself.&lt;/li&gt;
&lt;li&gt;Therefore, even though the toUpperCase() method is called on &lt;code&gt;a&lt;/code&gt;, the value of a itself remains unchanged and still contains the string "hello". When &lt;code&gt;console.log(a)&lt;/code&gt; is called, the output will be &lt;code&gt;"hello"&lt;/code&gt;, since the value of &lt;code&gt;a&lt;/code&gt; has not been modified by the previous call to toUpperCase().&lt;/li&gt;
&lt;li&gt;If you want to change the value of &lt;code&gt;a&lt;/code&gt; to the uppercase version of "hello", you need to assign the result of the toUpperCase() method back to a, like this:&lt;/li&gt;
&lt;li&gt;const a = "hello";&lt;/li&gt;
&lt;li&gt;a = a.toUpperCase();&lt;/li&gt;
&lt;li&gt;console.log(a); // "HELLO"&lt;/li&gt;
&lt;li&gt;In this case, the value of a will be &lt;code&gt;"HELLO"&lt;/code&gt;, since it has been assigned the result of calling toUpperCase() on the original string "hello".&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to ✈️&lt;br&gt;
Question 10&lt;/p&gt;




&lt;h3&gt;
  
  
  How many did you got right✅? Let me know in the comments 🤖
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmn03bmbr8diao1q52k2c.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmn03bmbr8diao1q52k2c.gif" alt="tom shy" width="498" height="368"&gt;&lt;/a&gt;&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>puzzle</category>
    </item>
    <item>
      <title>Setup NextJS with typescript, EsLint, prettier and husky</title>
      <dc:creator>Abhishek singh </dc:creator>
      <pubDate>Mon, 06 Jun 2022 12:01:36 +0000</pubDate>
      <link>https://dev.to/abhisheksrajput/setup-nextjs-with-typescript-eslint-prettier-and-husky-49lb</link>
      <guid>https://dev.to/abhisheksrajput/setup-nextjs-with-typescript-eslint-prettier-and-husky-49lb</guid>
      <description>&lt;p&gt;This is a short blog on setting up a project with NextJS, EsLint, prettier and husky.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Next.js is a React framework that gives you building blocks to create web applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;EsLint is a pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prettier is an opinionated code formatter that supports many different programming languages, like JavaScript. JSON. JSX.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Husky improves your git commits and more 🐶 woof!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  01 Setting up Nextjs with typescript
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app [project-name] --typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will setup nextjs project for you&lt;/p&gt;

&lt;h2&gt;
  
  
  02 Setting up Eslint in the project
&lt;/h2&gt;

&lt;p&gt;eslint comes pre-setup through &lt;code&gt;npx create-next-app&lt;/code&gt; we don't have to install eslint simply run the below command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init @eslint/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which will guide you through a series of configuration settings&lt;/p&gt;

&lt;p&gt;a. How would you like to use ESLint?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To check syntax only&lt;/li&gt;
&lt;li&gt;To check syntax and find problems&lt;/li&gt;
&lt;li&gt;To check syntax, find problems, and enforce code style&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;To check syntax, find problems, and enforce code style&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;since we not only want to find problems in our code we want to enforce a common code style (Airbnb)&lt;/p&gt;

&lt;p&gt;b. What type of modules does your project use?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript modules (import/export)&lt;/li&gt;
&lt;li&gt;CommonJS (require/exports)&lt;/li&gt;
&lt;li&gt;None of these&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript modules (import/export)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Note JavaScript modules (import/export): The ES module format is the official standard format to package JavaScript code for reuse and most modern web browsers natively support the modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note Node.js, however, supports the CommonJS module format by default. CommonJS modules-load using require(), and variables and functions export from a CommonJS module with module.exports.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;c. Which framework does your project use?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;Vue.js&lt;/li&gt;
&lt;li&gt;None of these&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;React&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;d. Does your project use TypeScript?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;yes/no&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;yes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;e. Where does your code run?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser&lt;/li&gt;
&lt;li&gt;Node&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Browser&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;f. How would you like to define a style for your project?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a popular style guide&lt;/li&gt;
&lt;li&gt;Answer questions about your style&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Use a popular style guide&lt;/p&gt;

&lt;p&gt;Airbnb: &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;https://github.com/airbnb/javascript&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since Airbnb is the most popular style guide and industry standard in most companies.&lt;/p&gt;

&lt;p&gt;g. What format do you want your config file to be in?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;YAML&lt;/li&gt;
&lt;li&gt;JSON&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;JSON&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will select JSON because it is preferred over other file formats&lt;/p&gt;

&lt;p&gt;h. Would you like to install them now?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No / Yes&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;i. Which package manager do you want to use?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npm&lt;/li&gt;
&lt;li&gt;yarn&lt;/li&gt;
&lt;li&gt;pnpm&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;npm&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  03 Now let's Setup prettier
&lt;/h2&gt;

&lt;p&gt;First lets install necessary packages for setting up prettier in our project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install prettier eslint-config-prettier eslint-plugin-prettier --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then go to &lt;code&gt;.eslintrc.json&lt;/code&gt; file and add following configurations to &lt;code&gt;"extends"&lt;/code&gt; property and &lt;code&gt;"plugins"&lt;/code&gt; property&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE The extends property value is either: a string that specifies a configuration(either a path to a config file, the name of a shareable config, eslint: recommended, or eslint: all ) or an array of strings where each additional configuration extends the preceding configurations.&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;{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "plugin:react/recommended",
    "next/core-web-vitals",
    "airbnb",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint", "prettier"],
  "rules": {}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now let's create a local prettier configuration file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .prettierrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And then add the following configuration to the &lt;code&gt;.prettierrc&lt;/code&gt; file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": false,
  "trailingComma": "es5",
  "printWidth": 80
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Install prettier in your local code editor in my case I'm using vscode.&lt;br&gt;
Then go to vscode settings and search for &lt;code&gt;Default Formatter&lt;/code&gt; change it to &lt;code&gt;Prettier-Code formatter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;after that make sure &lt;code&gt;format on save&lt;/code&gt; is turned on in your vscode settings this will format your code every time you save your file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  04. Now let's configure eslint rules to our liking
&lt;/h2&gt;

&lt;p&gt;first, let's install the package for Airbnb typescript configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install eslint-config-airbnb-typescript --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then add configurations to the &lt;code&gt;.eslintrc.json&lt;/code&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "plugin:react/recommended",
    "next/core-web-vitals",
    "airbnb",
    "airbnb-typescript",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module",
    "project": "./tsconfig.json"
  },
  "plugins": ["react", "@typescript-eslint", "prettier"],
  "rules": {
    // suppress errors for missing 'import React' in files
    "react/react-in-jsx-scope": ["off"],
    // gives warning if spread props getting passed to component ex. (...props)
    "react/jsx-props-no-spreading": ["warn"],
    // suppress errors for Function component is not a function declaration turning off allows us to use arrow functions
    "react/function-component-definition": ["off"]
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now add scripts in our &lt;code&gt;package.json&lt;/code&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  {
  "name": "final",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "check-format": "prettier --check .",
    "check-lint": "eslint . --ext ts --ext tsx --ext js",
    "check-types": "tsc --pretty --noEmit",
    "format": "prettier --write ."
  },
  "dependencies": {
    "next": "12.1.6",
    "react": "18.1.0",
    "react-dom": "18.1.0"
  },
  "devDependencies": {
    "@types/node": "17.0.40",
    "@types/react": "18.0.12",
    "@types/react-dom": "18.0.5",
    "@typescript-eslint/eslint-plugin": "^5.27.0",
    "@typescript-eslint/parser": "^5.27.0",
    "eslint": "^8.17.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-airbnb-typescript": "^17.0.0",
    "eslint-config-next": "12.1.6",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.30.0",
    "eslint-plugin-react-hooks": "^4.5.0",
    "prettier": "^2.6.2",
    "typescript": "4.7.3"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now let's add &lt;code&gt;.eslintignore&lt;/code&gt; and &lt;code&gt;.prettierignore&lt;/code&gt; file at the root of our project
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .eslintignore .prettierignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then ignore the following files and folder in both files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;/node_modules&lt;br&gt;
 next.config.js&lt;br&gt;
 .next&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now run scripts to check if any error is being thrown
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run check-format &amp;amp;&amp;amp; npm run check-lint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If all things went well no error should be thrown.&lt;/p&gt;
&lt;h2&gt;
  
  
  05. Now, let's set up husky in our project.
&lt;/h2&gt;

&lt;p&gt;First, run the following command in terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx husky-init &amp;amp;&amp;amp; npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should setup husky in our project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now add some configuration to our &lt;code&gt;pre-commit&lt;/code&gt; file under &lt;code&gt;.husky&lt;/code&gt; folder.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo '🏗️👷 Styling, testing and building your project before committing'

# Check Prettier standards
npm run check-format ||
(
    echo '🤢🤮🤢🤮
                Yaaaaaccccccckkkkkkkkkk 🤢🤮🤢🤮
            Prettier Check Failed. Please Run npm run format, add changes and try commit again.';
    false;
)

# Check ESLint Standards
npm run check-lint ||
(
        echo '😤🏀👋😤 Bla Bla Bla Bla 😤🏀👋😤 
                ESLint Check Failed. Make the required changes listed above, add changes and try to commit again.'
        false; 
)

# Check tsconfig standards
npm run check-types ||
(
    echo '🤡😂❌🤡 Failed to check the types. 🤡😂❌🤡
            Please Make the changes required above.'
    false;
)

# If everything passes... Now we can commit
echo '🤔🤔🤔🤔... Alright.... Code looks good to me... Trying to build now. 🤔🤔🤔🤔'

npm run build ||
(
    echo '❌👷🔨❌ Send Help Build has failed ❌👷🔨❌
            Next build failed: View the errors above to see why. 
    '
    false;
)

# If everything passes... Now we can commit
echo '✅✅✅✅ Yo you got this... I am committing this now. ✅✅✅✅'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now try to commit the following checks should be automatically done in our project before committing
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m 'test'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If all went well you should be able to commit your changes to your file&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
