<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by sai_2kiran_4 on Medium]]></title>
        <description><![CDATA[Stories by sai_2kiran_4 on Medium]]></description>
        <link>https://medium.com/@saikiranmanchala2000?source=rss-b61070921186------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HaTEeqnT-8-0tcHh</url>
            <title>Stories by sai_2kiran_4 on Medium</title>
            <link>https://medium.com/@saikiranmanchala2000?source=rss-b61070921186------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 26 May 2026 22:56:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saikiranmanchala2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Validation Form ReactJS_2025]]></title>
            <link>https://medium.com/@saikiranmanchala2000/validation-form-reactjs-2025-19e0cc790f5e?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e0cc790f5e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 16:37:07 GMT</pubDate>
            <atom:updated>2025-02-07T16:48:00.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5PhdJpgQNqCSJMnJ" /><figcaption>Validation</figcaption></figure><pre>import React, { useState } from &quot;react&quot;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;<br><br>function Validation() {<br>    const [formData, setFormData] = useState({<br>        name: &quot;&quot;,<br>        email: &quot;&quot;,<br>        password: &quot;&quot;,<br>        habits: {<br>            cricket: false,<br>            coding: false,<br>            javascript: false,<br>        },<br>    });<br><br>    const [errors, setErrors] = useState({<br>        name: &quot;&quot;,<br>        email: &quot;&quot;,<br>        password: &quot;&quot;,<br>        habits: &quot;&quot;,<br>    });<br><br>    const handleInputChange = (e) =&gt; {<br>        const { name, value, type, checked } = e.target;<br>        if (type === &quot;checkbox&quot;) {<br>            setFormData({<br>                ...formData,<br>                habits: {<br>                    ...formData.habits,<br>                    [name]: checked,<br>                },<br>            });<br>        } else {<br>            setFormData({<br>                ...formData,<br>                [name]: value,<br>            });<br>        }<br>    };<br><br>    const validateForm = () =&gt; {<br>        let isValid = true;<br>        const newErrors = {<br>            name: &quot;&quot;,<br>            email: &quot;&quot;,<br>            password: &quot;&quot;,<br>            habits: &quot;&quot;,<br>        };<br><br>        if (formData.name.trim() === &quot;&quot;) {<br>            newErrors.name = &quot;Name is required&quot;;<br>            isValid = false;<br>        } else if (!/^[a-zA-Z]+$/.test(formData.name)) {<br>            newErrors.name = &quot;Name should only contain alphabetic characters&quot;;<br>            isValid = false;<br>        }<br><br>        if (formData.email.trim() === &quot;&quot;) {<br>            newErrors.email = &quot;Email is required&quot;;<br>            isValid = false;<br>        } else if (<br>            !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(formData.email)<br>        ) {<br>            newErrors.email = &quot;Invalid email address&quot;;<br>            isValid = false;<br>        }<br><br>        if (formData.password.trim() === &quot;&quot;) {<br>            newErrors.password = &quot;Password is required&quot;;<br>            isValid = false;<br>        } else if (formData.password.length &lt; 8) {<br>            newErrors.password = &quot;Password should be at least 8 characters long&quot;;<br>            isValid = false;<br>        }<br><br>        if (!formData.habits.cricket &amp;&amp; !formData.habits.coding &amp;&amp; !formData.habits.javascript) {<br>            newErrors.habits = &quot;At least one habit must be selected&quot;;<br>            isValid = false;<br>        }<br><br>        setErrors(newErrors);<br>        return isValid;<br>    };<br><br>    const handleSubmit = (e) =&gt; {<br>        e.preventDefault();<br><br>        if (validateForm()) {<br>            console.log(&quot;Form submitted successfully:&quot;, formData);<br>        }<br>    };<br><br>    return (<br>        &lt;div className=&quot;container mt-5&quot;&gt;<br>            &lt;div className=&quot;card p-4&quot;&gt;<br>                &lt;h2 className=&quot;text-center&quot;&gt;Registration Form&lt;/h2&gt;<br>                &lt;form onSubmit={handleSubmit}&gt;<br>                    &lt;div className=&quot;mb-3&quot;&gt;<br>                        &lt;label className=&quot;form-label&quot;&gt;Name:&lt;/label&gt;<br>                        &lt;input<br>                            type=&quot;text&quot;<br>                            className={`form-control ${errors.name ? &quot;is-invalid&quot; : &quot;&quot;}`}<br>                            name=&quot;name&quot;<br>                            value={formData.name}<br>                            onChange={handleInputChange}<br>                        /&gt;<br>                        {errors.name &amp;&amp; &lt;div className=&quot;invalid-feedback&quot;&gt;{errors.name}&lt;/div&gt;}<br>                    &lt;/div&gt;<br><br>                    &lt;div className=&quot;mb-3&quot;&gt;<br>                        &lt;label className=&quot;form-label&quot;&gt;Email:&lt;/label&gt;<br>                        &lt;input<br>                            type=&quot;email&quot;<br>                            className={`form-control ${errors.email ? &quot;is-invalid&quot; : &quot;&quot;}`}<br>                            name=&quot;email&quot;<br>                            value={formData.email}<br>                            onChange={handleInputChange}<br>                        /&gt;<br>                        {errors.email &amp;&amp; &lt;div className=&quot;invalid-feedback&quot;&gt;{errors.email}&lt;/div&gt;}<br>                    &lt;/div&gt;<br><br>                    &lt;div className=&quot;mb-3&quot;&gt;<br>                        &lt;label className=&quot;form-label&quot;&gt;Password:&lt;/label&gt;<br>                        &lt;input<br>                            type=&quot;password&quot;<br>                            className={`form-control ${errors.password ? &quot;is-invalid&quot; : &quot;&quot;}`}<br>                            name=&quot;password&quot;<br>                            value={formData.password}<br>                            onChange={handleInputChange}<br>                        /&gt;<br>                        {errors.password &amp;&amp; (<br>                            &lt;div className=&quot;invalid-feedback&quot;&gt;{errors.password}&lt;/div&gt;<br>                        )}<br>                    &lt;/div&gt;<br><br>                    &lt;div className=&quot;mb-3&quot;&gt;<br>                        &lt;label className=&quot;form-label&quot;&gt;Habits:&lt;/label&gt;<br>                        &lt;div className=&quot;form-check&quot;&gt;<br>                            &lt;input<br>                                type=&quot;checkbox&quot;<br>                                className=&quot;form-check-input&quot;<br>                                name=&quot;cricket&quot;<br>                                checked={formData.habits.cricket}<br>                                onChange={handleInputChange}<br>                            /&gt;<br>                            &lt;label className=&quot;form-check-label&quot;&gt;Cricket&lt;/label&gt;<br>                        &lt;/div&gt;<br>                        &lt;div className=&quot;form-check&quot;&gt;<br>                            &lt;input<br>                                type=&quot;checkbox&quot;<br>                                className=&quot;form-check-input&quot;<br>                                name=&quot;coding&quot;<br>                                checked={formData.habits.coding}<br>                                onChange={handleInputChange}<br>                            /&gt;<br>                            &lt;label className=&quot;form-check-label&quot;&gt;Coding&lt;/label&gt;<br>                        &lt;/div&gt;<br>                        &lt;div className=&quot;form-check&quot;&gt;<br>                            &lt;input<br>                                type=&quot;checkbox&quot;<br>                                className=&quot;form-check-input&quot;<br>                                name=&quot;javascript&quot;<br>                                checked={formData.habits.javascript}<br>                                onChange={handleInputChange}<br>                            /&gt;<br>                            &lt;label className=&quot;form-check-label&quot;&gt;JavaScript&lt;/label&gt;<br>                        &lt;/div&gt;<br>                        {errors.habits &amp;&amp; &lt;div className=&quot;text-danger&quot;&gt;{errors.habits}&lt;/div&gt;}<br>                    &lt;/div&gt;<br><br>                    &lt;button type=&quot;submit&quot; className=&quot;btn btn-primary w-100&quot;&gt;<br>                        Register<br>                    &lt;/button&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>    );<br>}<br><br>export default Validation;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e0cc790f5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SignIn SignUp In ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/signin-signup-in-reactjs-2383d26c6fea?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/2383d26c6fea</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 11:15:21 GMT</pubDate>
            <atom:updated>2024-10-20T11:15:21.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iQlw9Kvvt7SxVuI_" /><figcaption>SignIn SignUp</figcaption></figure><pre>npm install bootstrap<br><br>import &#39;bootstrap-icons/font/bootstrap-icons.css&#39;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;</pre><pre>import React, { useState } from &quot;react&quot;;<br><br>function SignUpUi() {<br>  const [display, setDisplay] = useState(false);<br><br>  return (<br>    &lt;div className=&quot;container mt-4&quot;&gt;<br>      &lt;div className=&quot;row justify-content-center&quot;&gt;<br>        &lt;div className=&quot;col-md-6&quot;&gt;<br>          &lt;div className=&quot;text-center mb-4&quot;&gt;<br>            &lt;button<br>              className=&quot;btn btn-primary me-2&quot;<br>              onClick={() =&gt; setDisplay(true)}<br>            &gt;<br>              Sign Up<br>            &lt;/button&gt;<br>            &lt;button<br>              className=&quot;btn btn-secondary&quot;<br>              onClick={() =&gt; setDisplay(false)}<br>            &gt;<br>              Sign In<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br><br>          {display ? (<br>            &lt;div&gt;<br>              &lt;h1 className=&quot;text-center mb-4&quot;&gt;Sign Up&lt;/h1&gt;<br>              &lt;form&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    placeholder=&quot;First Name&quot;<br>                    className=&quot;form-control&quot;<br>                    autoComplete=&#39;off&#39;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    placeholder=&quot;Last Name&quot;<br>                    className=&quot;form-control&quot;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    type=&quot;email&quot;<br>                    placeholder=&quot;Email&quot;<br>                    className=&quot;form-control&quot;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    type=&quot;password&quot;<br>                    placeholder=&quot;Password&quot;<br>                    className=&quot;form-control&quot;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;button className=&quot;btn btn-success w-100&quot;&gt;Sign Up&lt;/button&gt;<br>              &lt;/form&gt;<br>            &lt;/div&gt;<br>          ) : (<br>            &lt;div&gt;<br>              &lt;h1 className=&quot;text-center mb-4&quot;&gt;Sign In&lt;/h1&gt;<br>              &lt;form&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    type=&quot;email&quot;<br>                    placeholder=&quot;Email&quot;<br>                    className=&quot;form-control&quot;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;div className=&quot;mb-3&quot;&gt;<br>                  &lt;input<br>                    type=&quot;password&quot;<br>                    placeholder=&quot;Password&quot;<br>                    className=&quot;form-control&quot;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;button className=&quot;btn btn-primary w-100&quot;&gt;Sign In&lt;/button&gt;<br>              &lt;/form&gt;<br>            &lt;/div&gt;<br>          )}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default SignUpUi;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2383d26c6fea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Input Search In ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/input-search-in-reactjs-06ea5fe15d47?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/06ea5fe15d47</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 10:57:51 GMT</pubDate>
            <atom:updated>2024-10-20T10:58:40.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4MLGg89wIaJZTwdh" /><figcaption>Input Search</figcaption></figure><pre>npm install bootstrap<br><br>import &#39;bootstrap-icons/font/bootstrap-icons.css&#39;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;</pre><pre>import React, { useState } from &quot;react&quot;;<br><br>function InputWithSearch() {<br>  const [val, setVal] = useState(&#39;&#39;);<br>  const data = [<br>    &quot;Java&quot;,<br>    &quot;JavaScript&quot;,<br>    &quot;React js&quot;,<br>    &quot;Python&quot;,<br>    &quot;C&quot;,<br>    &quot;C++&quot;,<br>  ];<br><br>  return (<br>    &lt;div className=&quot;container mt-4&quot;&gt;<br>      &lt;div className=&quot;row&quot;&gt;<br>        &lt;div className=&quot;col-md-6&quot;&gt;<br>          &lt;input<br>            list=&quot;data&quot;<br>            className=&quot;form-control&quot;<br>            onChange={(e) =&gt; setVal(e.target.value)}<br>            placeholder=&quot;Search&quot;<br>          /&gt;<br>          &lt;datalist id=&quot;data&quot;&gt;<br>            {data.map((op, index) =&gt; &lt;option key={index}&gt;{op}&lt;/option&gt;)}<br>          &lt;/datalist&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&quot;row mt-3&quot;&gt;<br>        &lt;div className=&quot;col-md-6&quot;&gt;<br>          &lt;h1&gt;{val}&lt;/h1&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default InputWithSearch;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06ea5fe15d47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Select Option In ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/select-option-in-reactjs-38f531c9bc25?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/38f531c9bc25</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 10:10:15 GMT</pubDate>
            <atom:updated>2024-10-20T10:10:15.783Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QcWML84qb5IA5U1r" /><figcaption>Select Option</figcaption></figure><pre>npm install bootstrap<br><br>import &#39;bootstrap-icons/font/bootstrap-icons.css&#39;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;</pre><pre>import React, { useState } from &quot;react&quot;;<br><br>function DynamicSelectOption() {<br>  const [val, setVal] = useState(&#39;&#39;);<br>  const data = [&quot;Prabhas&quot;, &quot;Surya&quot;, &quot;NTR&quot;];<br><br>  return (<br>    &lt;div&gt;<br>      &lt;select<br>        className=&quot;form-select mt-3 ms-2 w-25&quot;<br>        aria-label=&quot;Default select example&quot;<br>        value={val}<br>        onChange={e =&gt; setVal(e.target.value)}<br>      &gt;<br>        {<br>          data.map((da, i) =&gt; (<br>            &lt;option key={i} value={da}&gt;{da}&lt;/option&gt; // Added the return here<br>          ))<br>        }<br>      &lt;/select&gt;<br>      &lt;h2 className=&quot;mt-3 ms-2&quot;&gt;{val}&lt;/h2&gt;<br>    &lt;/div&gt;<br>    <br>  );<br>}<br><br>export default DynamicSelectOption;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38f531c9bc25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CopyText_ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/copytext-reactjs-b632c73c881e?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/b632c73c881e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 07:30:55 GMT</pubDate>
            <atom:updated>2024-10-20T07:30:55.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I59aZEz2thPy4xev" /><figcaption>CopyText</figcaption></figure><pre>import React, { useState } from &#39;react&#39;;<br><br>const CopyText = () =&gt; {<br>  const [copy, setCopy] = useState(&#39;&#39;);<br><br>  const handleCopy = () =&gt; {<br>    navigator.clipboard.writeText(copy);<br>    alert(&#39;Copied..&#39;);<br>  };<br><br>  return (<br>  &lt;&gt;<br>    &lt;div className=&quot;d-flex align-items-center mt-5&quot;&gt;<br>      &lt;input<br>        type=&quot;text&quot;<br>        className=&quot;form-control w-25 me-2 ms-2&quot;<br>        placeholder=&quot;Username&quot;<br>        aria-label=&quot;Username&quot;<br>        value={copy}<br>        onChange={(e) =&gt; setCopy(e.target.value)}<br>      /&gt;<br>      &lt;button type=&quot;button&quot; className=&quot;btn btn-success&quot; onClick={handleCopy}&gt;<br>        CopyText<br>      &lt;/button&gt;<br>      <br>    &lt;/div&gt;<br>    &lt;div className=&quot;input-group mt-3 w-25 ms-2&quot;&gt;<br>    &lt;textarea className=&quot;form-control &quot; aria-label=&quot;With textarea&quot;&gt;&lt;/textarea&gt;<br>  &lt;/div&gt;<br>  &lt;/&gt;<br>  );<br>};<br><br>export default CopyText;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b632c73c881e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GoogleMap_ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/googlemap-reactjs-ba365e75c0af?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba365e75c0af</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 06:16:26 GMT</pubDate>
            <atom:updated>2024-10-20T06:16:26.472Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sswA-tuzGcsKTSF2" /><figcaption>GoogleMap</figcaption></figure><pre>import React, { useEffect } from &quot;react&quot;;<br><br>function GoogleMap(){<br>    useEffect(()=&gt;{<br>        const ifameData=document.getElementById(&quot;iframeId&quot;)<br>        const lat=17.4375;<br>        const lon=78.4482;<br><br>        ifameData.src=`https://maps.google.com/maps?q=${lat},${lon}&amp;hl=es;&amp;output=embed`<br>    })<br>    return(<br>        &lt;div&gt;<br>            &lt;iframe id=&quot;iframeId&quot; height=&quot;500px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;<br>        &lt;/div&gt;<br>    );<br>}<br>export default GoogleMap;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba365e75c0af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ShowHidePassword_ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/showhidepassword-reactjs-71e5658ddb83?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e5658ddb83</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 05:57:35 GMT</pubDate>
            <atom:updated>2024-10-20T05:57:35.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lKotG5YXDB8UhW24" /><figcaption>ShowHidePassword</figcaption></figure><pre>npm install bootstrap<br><br>import &#39;bootstrap-icons/font/bootstrap-icons.css&#39;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;</pre><pre>import React, { useState } from &quot;react&quot;;<br><br>function PasswordShowHide() {<br>  const [show, setShow] = useState(false);<br><br>  const handleShow = () =&gt; {<br>    setShow(!show);<br>  };<br><br>  return (<br>    &lt;div className=&quot;container&quot;&gt;<br>      &lt;input type={show ? &quot;text&quot; : &quot;password&quot;} /&gt;<br>      &lt;i<br>        className={`bi ${show ? &quot;bi-eye&quot; : &quot;bi-eye-slash&quot;}`} <br>        style={{ cursor: &quot;pointer&quot;, marginLeft: &quot;10px&quot; }}<br>        onClick={handleShow}<br>      &gt;&lt;/i&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default PasswordShowHide;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e5658ddb83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Model Popup_ReactJs]]></title>
            <link>https://medium.com/@saikiranmanchala2000/model-popup-reactjs-5610074580bf?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/5610074580bf</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 05:49:55 GMT</pubDate>
            <atom:updated>2024-10-20T05:50:38.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wVB71Z8fjtmnNgrg" /><figcaption>Popup</figcaption></figure><pre>npm install bootstrap<br><br>import &#39;bootstrap-icons/font/bootstrap-icons.css&#39;;<br>import &quot;bootstrap/dist/css/bootstrap.min.css&quot;;</pre><pre>import React, { useEffect, useState } from &#39;react&#39;;<br><br>const Popup = () =&gt; {<br>  const [popup, setPopup] = useState(false);<br><br>  const openPopup = () =&gt; {<br>    setPopup(true); <br>  };<br><br>  const closePopup = () =&gt; {<br>    setPopup(false);<br>  };<br><br>  useEffect(()=&gt;{<br>    document.addEventListener(&quot;keyup&quot;,(e)=&gt;{<br>        console.log(e.code,&quot;key&quot;)<br>        if(e.code===&quot;Enter&quot;){<br>            setPopup(true)<br>        }<br>        else if(e.code===&quot;ShiftLeft&quot;){<br>            setPopup(false)<br>        }<br>    })<br>})<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button type=&quot;button&quot; className=&quot;btn btn-primary&quot; onClick={openPopup}&gt;<br>        Model Popup<br>      &lt;/button&gt;<br><br>      {popup &amp;&amp; (<br>        &lt;div className=&quot;modal show d-block&quot; tabIndex=&quot;-1&quot; style={{ backgroundColor: &#39;rgba(0,0,0,0.5)&#39; }}&gt;<br>          &lt;div className=&quot;modal-dialog&quot;&gt;<br>            &lt;div className=&quot;modal-content&quot;&gt;<br>              &lt;div className=&quot;modal-header&quot;&gt;<br>                &lt;h5 className=&quot;modal-title&quot;&gt;Sai Kiran Manchala&lt;/h5&gt;<br>                &lt;button type=&quot;button&quot; className=&quot;btn-close&quot; onClick={closePopup} aria-label=&quot;Close&quot;&gt;&lt;/button&gt;<br>              &lt;/div&gt;<br>              &lt;div className=&quot;modal-body&quot;&gt;Associate Software Engineer..&lt;/div&gt;<br>              &lt;div className=&quot;modal-footer&quot;&gt;<br>                &lt;button type=&quot;button&quot; className=&quot;btn btn-secondary&quot; onClick={closePopup}&gt;<br>                  Close<br>                &lt;/button&gt;<br>                &lt;button type=&quot;button&quot; className=&quot;btn btn-primary&quot;&gt;Save changes&lt;/button&gt;<br>              &lt;/div&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Popup;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5610074580bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript_Part-1_2024]]></title>
            <link>https://medium.com/@saikiranmanchala2000/javascript-part-1-2024-bda76b291f3a?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/bda76b291f3a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 09:39:31 GMT</pubDate>
            <atom:updated>2024-10-08T09:39:31.822Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rT_mX8JBWHM1_7kF" /><figcaption>JavaScript</figcaption></figure><p><strong>1.What are the different datatypes in JavaScript ?</strong></p><p><strong>**Primitive Data Types</strong>:<br>=&gt;Primitive data types are <strong>immutable</strong> (cannot be altered after creation) and are stored directly in the <strong>memory stack</strong>.</p><p><strong>1.Number: </strong>Represents <strong>numeric values</strong> (integers and floating-point numbers).</p><pre>let age = 25;         // Integer<br>let price = 19.99;    // Floating-point number<br>console.log(age);     // Output: 25<br>console.log(price);   // Output: 19.99</pre><p><strong>2.String: </strong>Represents a sequence of <strong>characters</strong>, used for textual data.</p><pre>let name = &quot;sai&quot;;      // Double quotes<br>let greeting = &#39;Hello&#39;;  // Single quotes<br>console.log(name);       // Output: sai<br>console.log(greeting);   // Output: Hello</pre><p><strong>3.Boolean</strong>: Represents a <strong>logical entity with two possible values</strong>: <strong>true</strong> or <strong>false</strong>.</p><pre>let isStudent = true;<br>let hasGraduated = false;<br>console.log(isStudent);     // Output: true<br>console.log(hasGraduated);  // Output: false</pre><p><strong>4.Undefined: </strong>Means the <strong>variable has been declared</strong> but <strong>not assigned</strong> any <strong>value</strong> <strong>yet</strong>.</p><pre>let score;<br>console.log(score);  // Output: undefined</pre><p><strong>5.Null: </strong>If we assign <strong>null to a variable,</strong> it means it <strong>will</strong> <strong>not have any value.</strong></p><pre>let user = null;<br>console.log(user);  // Output: null</pre><p><strong>6.Symbol(Introduced in ES6) :</strong>Symbols are <strong>often</strong> used to<strong> create unique object keys.</strong></p><pre>let symbol1 = Symbol(&#39;id&#39;);<br>let symbol2 = Symbol(&#39;id&#39;);<br>console.log(symbol1 === symbol2);  // Output: false (each symbol is unique)</pre><p><strong>7.BigInt (introduced in ES2020): It </strong>Allows you to represent <strong>numbers larger than the Number </strong>type can handle (which has a maximum limit).</p><pre>let bigNumber = 123456789012345678901234567890n;<br>console.log(bigNumber);  // Output: 123456789012345678901234567890n</pre><p><strong>**Non-Primitive (Reference) Data Types</strong>:<br>=&gt;Non-primitive data types are <strong>mutable</strong> and are stored in the <strong>heap(</strong>memory where <strong>dynamically allocated objects</strong> are stored.<strong>).<br>=&gt;</strong>Variables that refer to <strong>non-primitive types</strong> do <strong>not store the actual value</strong> but a <strong>reference to the location in memory</strong> where the <strong>value is stored.</strong></p><p><strong>1.Object: </strong>Used to <strong>store collections of data in key-value pairs.</strong></p><pre>let person = {<br>  name: &quot;Sai&quot;,<br>  age: 24,<br>  isEmployed: true<br>};<br>console.log(person.name);   // Output: Sai<br>console.log(person.age);    // Output: 24</pre><p><strong>2.Array:</strong> A special type of <strong>object that holds an ordered collection of values</strong> (which can be of any type).</p><pre>let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Orange&quot;];<br>console.log(fruits[0]);  // Output: Apple<br>console.log(fruits[2]);  // Output: Orange</pre><p><strong>2. What is Hoisting in JavaScript?</strong></p><p>=&gt;In other <strong>scripting/server side languages</strong>, <strong>variables</strong> or <strong>functions</strong> must be <strong>declared</strong> <strong>before</strong> <strong>using</strong> <strong>it</strong>.<br>=&gt;In JavaScript, <strong>variables and functions </strong>can be used <strong>before declaring it</strong>. =&gt;The JavaScript compiler moves all the <strong>declarations</strong> of <strong>variables</strong> and <strong>functions</strong> <strong>on top</strong>. so there <strong>will not be any error.</strong> This is called <strong>hoisting.</strong></p><pre>console.log(x);  // Output: undefined<br>var x = 5;<br>console.log(x);  // Output: 5</pre><p>=&gt;In this example, JavaScript <strong>hoists</strong> the declaration of var x to the top of the scope. So, internally, the code is interpreted like this:</p><pre>var x;  // Declaration is hoisted<br>console.log(x);  // Output: undefined (x is declared but not initialized yet)<br>x = 5;  // Initialization happens here<br>console.log(x);  // Output: 5</pre><p>=&gt;Variables defined with <strong>let and const are hoisted to the top of the block,</strong> but <strong>not initialized. <br>=&gt;Let and const are also hoisted</strong> but <strong>we cant access</strong> them until they are <strong>assigned</strong> because they are in <strong>Temporal dead zone.</strong></p><pre>var a;    // Declaring a variable using `var`<br>let b;    // Declaring a variable using `let`<br>const c;  // Declaring a constant variable using `const` (must be initialized at the time of declaration)</pre><pre>x = 10;   // Assigning the value 10 to variable `x`<br>y = 20;   // Assigning the value 20 to variable `y`</pre><pre>var a = 10;    // Declaration and assignment in a single step<br>let b = 20;    // Declaration and assignment using `let`<br>const c = 30;  // Declaration and assignment using `const`</pre><p><strong>Various things hoisted in JavaScript:</strong></p><pre>Function declarations: Fully hoisted.<br>var - Hoisted<br>Arrow functions: Not hoisted<br>Anonymous Function expressions: Not hoisted<br>let and const - Hoisted but not initialized. (Temporal dead zo<br>class declarations - Hoisted but not initialized.</pre><p><strong>reference: </strong><a href="https://stackabuse.com/hoisting-in-javascript/"><strong>https://stackabuse.com/hoisting-in-javascript/</strong></a></p><p><strong>3.What is temporal dead zone?</strong></p><p>=&gt;It is a specific <strong>time period in the execution of JavaScript code</strong> where the <strong>variables declared with let and const </strong>exists but <strong>cannot</strong> be <strong>accessed</strong> until the <strong>value is assigned. </strong><br>=&gt;Any attempt to access them result in <strong>reference errors.</strong></p><pre>console.log(x);  // ReferenceError: Cannot access &#39;x&#39; before initialization<br>let x = 10;<br>console.log(x);  // Output: 10</pre><p><strong>4.What are the differences let, var and const ?</strong></p><p><strong>**Scope:</strong> <br>=&gt;Variables declared with <strong>var are function scoped.</strong>( available through out the function where its declared ) or <strong>global scoped</strong>( if defined outside the function ).<br>=&gt; <strong>Variables declared with let and const are block scoped.</strong> <br><strong>**Reassignment:</strong> <br>=&gt;<strong>var and let can be reassigned. <br>=&gt;const cannot be reassigned</strong>.<br><strong>**Hoisting:</strong> <br>=&gt;<strong>var gets hoisted </strong>and <strong>initialized</strong> with <strong>undefined.<br>=&gt;</strong>let and const — gets hoisted to the top of the scope <strong>but does not get assigned</strong> any <strong>value</strong>.(<strong>temporal dead zone</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*9n6n37ESH7Mp2AxadZClIw.png" /><figcaption>Figure:1</figcaption></figure><p><strong>5.What is the Diff b/w Function Scope &amp; Block-Scope &amp; Global Scope?</strong></p><p>**<strong>Function Scope:<br>=&gt;Function scope</strong> means that a <strong>variable declared inside a function</strong> is only accessible <strong>within that function.<br>=&gt; </strong>It <strong>cannot be accessed from outside the function.<br>=&gt;</strong>Variables declared with <strong>var are function-scoped</strong>. <br>=&gt;This means they are <strong>available throughout the entire function</strong> in which they are <strong>declared</strong>, <strong>regardless</strong> of <strong>block boundaries within the function</strong>.</p><pre>function exampleFunction() {<br>    var message = &quot;Hello, World!&quot;;<br>    console.log(message);  // Output: Hello, World!<br>}<br><br>exampleFunction();<br><br>console.log(message);  // Error: message is not defined</pre><p><strong>Var inside a block:</strong></p><pre>function testVarScope() {<br>    if (true) {<br>        var insideIf = &quot;I&#39;m inside if-block&quot;;<br>    }<br>    console.log(insideIf);  // Output: I&#39;m inside if-block<br>}<br><br>testVarScope();</pre><p><strong>**Block Scope:<br>=&gt;Block scope</strong> means that a variable <strong>declared inside a block</strong> (a pair of {} braces) is only <strong>accessible within that block </strong>and is <strong>not accessible outside of</strong> it.<br>=&gt;Variables declared with <strong>let and const</strong> are <strong>block-scoped</strong>.</p><pre>{<br>    let blockScopedVariable = &quot;I&#39;m block-scoped!&quot;;<br>    console.log(blockScopedVariable);  // Output: I&#39;m block-scoped!<br>}<br><br>console.log(blockScopedVariable);  // Error: blockScopedVariable is not defined</pre><p><strong>let and const in an if block:</strong></p><pre>function testLetScope() {<br>    if (true) {<br>        let insideIf = &quot;I&#39;m inside if-block&quot;;<br>        const pi = 3.14;<br>        console.log(insideIf);  // Output: I&#39;m inside if-block<br>        console.log(pi);  // Output: 3.14<br>    }<br>    console.log(insideIf);  // Error: insideIf is not defined<br>    console.log(pi);  // Error: pi is not defined<br>}<br><br>testLetScope();</pre><p><strong>**Global Scope:<br>=&gt;</strong>The <strong>global scope</strong> is the <strong>outermost</strong> scope in JavaScript, <strong>where variables and functions that are declared outside of any function or block</strong> can be <strong>accessed</strong> from anywhere in the code.<br>=&gt;<strong>Variables declared</strong> in the <strong>global scope are available throughout the entire program, </strong>including within functions and blocks.</p><pre>var globalVar = &quot;I am a global variable&quot;;<br><br>function accessGlobalVar() {<br>    console.log(globalVar);  // Output: I am a global variable<br>}<br><br>accessGlobalVar();<br>console.log(globalVar);  // Output: I am a global variable</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*kQVq14tBwsuzG1uitlluCg.png" /><figcaption>Figure :2</figcaption></figure><p><strong>6.List out some key features of ES6 ?</strong></p><p><strong>1.Arrow functions <br>2. Let and Const declarations.<br>3. Destructuring assignment <br>4. Default parameters <br>5. Template literals<br>6. Spread and Rest operators<br>7. Promises <br>8. Classes <br>9. Modules <br>10. Map, Set, Weakmap, Weakset</strong></p><p><strong>7.What is arrow functions in JavaScript and Limitations?</strong></p><p>=&gt;Arrow functions are<strong> introduced in ES6.</strong> <br>=&gt;They are <strong>simple and shorter way</strong> to write <strong>functions</strong> in <strong>JavaScript</strong>.<br>1.Arrow <strong>functions</strong> cannot be <strong>accessed before initialization</strong> <br>2. Arrow function <strong>does not have access to arguments object</strong> <br>3. Arrow functions <strong>cannot</strong> be used as <strong>constructors</strong>. Using them with the <strong>new keyword</strong> to create instances throws a Type Error.<br>4. Arrow functions cannot be used as <strong>generator</strong> <strong>functions</strong>.</p><pre>function square(a) {<br>    return a * a;<br>}<br><br>let square = (a) =&gt; { return a * a; }<br><br> **if the function body has only one statement that it returns, we can skip curly braces {} and the return statement:<br>let square = (a) =&gt; a * a</pre><p><strong>Reference</strong>: <a href="https://stackabuse.com/arrow-functions-in-javascript/"><strong>https://stackabuse.com/arrow-functions-in-javascript/</strong></a><strong><br></strong>Arrow functions + this combination questions will be asked here. Please explore on this combinations.</p><pre>function Person() {<br>    this.age = 0;  // Initializing the age property of the Person instance<br><br>    setInterval(() =&gt; {<br>        this.age++; // Incrementing the age property<br>        console.log(this.age); // Logging the current age<br>    }, 1000); // The function runs every 1000 milliseconds (1 second)<br>}<br><br>const person = new Person(); // Creating a new Person instance</pre><p><strong>8.What’s the spread operator in JavaScript?</strong></p><p>=&gt;Spread operator is <strong>used to spread</strong> or <strong>expand the elements</strong> of <strong>an iterable</strong> like <strong>array</strong> or <strong>string</strong> into <strong>individual</strong> <strong>elements</strong>.</p><pre>const names=[&quot;devaiah&quot;,&quot;malleshwari&quot;,&quot;shiva&quot;,&quot;ravali&quot;,&quot;sai&quot;]<br>console.log(names)<br>console.log(...names)<br>console.log([...names])<br><br>O/P: <br>[&quot;devaiah&quot;, &quot;malleshwari&quot;, &quot;shiva&quot;, &quot;ravali&quot;, &quot;sai&quot;]<br>&quot;devaiah&quot;, &quot;malleshwari&quot;, &quot;shiva&quot;, &quot;ravali&quot;, &quot;sai&quot;<br>[&quot;devaiah&quot;, &quot;malleshwari&quot;, &quot;shiva&quot;, &quot;ravali&quot;, &quot;sai&quot;]</pre><p><strong>Combining Array:</strong></p><pre>let spread1 = [&#39;Devaiah&#39;, &#39;Malleshwari&#39;];<br>let spread2 = [&#39;shiva&#39;, &#39;ravalika&#39;, &#39;saikiran&#39;];<br>let spread = [...spread1, ...spread2];<br>console.log(spread);<br><br>O/P: [&quot;Devaiah&quot;, &quot;Malleshwari&quot;, &quot;shiva&quot;, &quot;ravalika&quot;, &quot;saikiran&quot;]<br><br>**We can also use the spread operator inside the Array.push() method to push the contents of one array into another<br><br>let arr1 = [&#39;Devaiah&#39;, &#39;Malleshwari&#39;];<br>let arr2 = [&#39;shiva&#39;, &#39;ravalika&#39;, &#39;saikiran&#39;];<br>arr1.push(...arr2);<br>console.log(arr1);<br><br>O/P: [&quot;Devaiah&quot;, &quot;Malleshwari&quot;, &quot;shiva&quot;, &quot;ravalika&quot;, &quot;saikiran&quot;]</pre><p><strong>Copying Array and Object:</strong></p><pre>let spread1 = [&#39;Devaiah&#39;, &#39;Malleshwari&#39;];<br>console.log(spread1)<br>spread1.push(&quot;shiva&quot;,&quot;raalika&quot;,&quot;saikiran&quot;);<br>console.log(spread1)<br><br>O/P: <br>[&quot;Devaiah&quot;, &quot;Malleshwari&quot;]<br>[&quot;Devaiah&quot;, &quot;Malleshwari&quot;, &quot;shiva&quot;, &quot;raalika&quot;, &quot;saikiran&quot;]<br><br>or<br><br>let arr1 = [&#39;Ravalika&#39;, &#39;SaiKiran&#39;, &#39;Shiva&#39;];<br>let arr2 = [...arr1, &#39;Malleshwari&#39;, &#39;Devaiah&#39;];<br>console.log(arr2);<br><br>O/P:<br>[&#39;Ravalika&#39;, &#39;SaiKiran&#39;, &#39;Shiva&#39;, &#39;Malleshwari&#39;, &#39;Devaiah&#39;]<br><br>*With Objects*<br><br>let o1 = { name: &quot;saikiran&quot;,age: 24 };<br>let o2 = { village: &quot;potharam&quot;, designation: &quot;Full stack Developer&quot;, ...o1 };<br>console.log(o2);<br><br>O/P:<br>{<br>  age: 24,<br>  designation: &quot;Full stack Developer&quot;,<br>  name: &quot;saikiran&quot;,<br>  village: &quot;potharam&quot;<br>}<br><br><br>const billing = { billingContact: &#39;0987654321&#39;, billingAddress: &#39;street no 123, xyz city&#39; };<br>const shipping = { shippingContact: &#39;123456789&#39;, shippingAddress: &#39;street no 999, abc city&#39; };<br>const custInfo = { ...billing, ...shipping };<br>console.log(custInfo);<br><br>O/P:<br>{<br>  billingContact: &#39;0987654321&#39;,<br>  billingAddress: &#39;street no 123, xyz city&#39;,<br>  shippingContact: &#39;123456789&#39;,<br>  shippingAddress: &#39;street no 999, abc city&#39;<br>}</pre><p><strong>Passing array of values as individual arguments to a function:</strong></p><pre>function doSum(times, ...items) {<br>    let sum = 0;<br>    for (let item of items){<br>        sum += item*times;<br>    }<br>    return sum;<br>}<br><br>console.log(doSum(1, 1));<br>console.log(doSum(2, 1, 2));</pre><p><strong>10.What is rest operator in JavaScript ?</strong></p><p>=&gt;Rest operator is used to <strong>multiple elements</strong> into <strong>single array or</strong> <strong>object</strong>.<br>=&gt; This is useful when we don’t know <strong>how many parameters a function</strong> <strong>may receive</strong> and you want to <strong>capture</strong> all of <strong>them as an array</strong>.</p><pre>var student ={<br>  name: &quot;Sai&quot;,<br>  age : 24,<br>  hobbies : [&quot;Vollyball&quot;, &quot;Cricket&quot;]<br>}<br><br>const age = student.age; //earlier we like this<br>console.log(age) //10<br><br>const {age, ...rest} = student; //using destructuring<br>console.log(age, rest) //100 {&quot;name&quot;: &quot;Sai&quot;, &quot;hobbies&quot;:[&quot;Vollyball&quot;, &quot;Cricket&quot;]}<br><br>const {...rest} = student;<br>console.log(rest) //{&quot;name&quot;: &quot;Sai&quot;, &quot;age&quot;: 24, &quot;hobbies&quot;:[&quot;Vollyball&quot;, &quot;Cricket&quot;]}<br><br>*Functions*<br><br>function Example(...args){<br>console.log(args)<br>}<br>Example(1,2,3,4);<br><br>O/P: [1, 2, 3, 4]</pre><p><strong>11.What is destructuring ?</strong></p><p>=&gt;It is introduced in Es6.<br>=&gt; It allows us to <strong>assign</strong> the <strong>object</strong> <strong>properties</strong> and <strong>array values</strong> into <strong>variables.</strong></p><pre>let Technology={<br>techName:&quot;react js&quot;,<br>version:19,<br>developedBy:&quot;Google&quot;<br>}<br><br>const destruct = Technology.techName;<br>console.log(destruct)<br><br>O/P:&quot;react js&quot;<br><br><br>let Technology={<br>techName:&quot;react js&quot;,<br>version:19,<br>developedBy:&quot;Google&quot;<br>}<br><br>const {techName,version,developedBy} =Technology <br><br>******************************************************<br> <br><br>const {name, technologys} = {<br>    name: &#39;sAI&#39;,<br>    technologys: {<br>        charged: [&#39;React &#39;, &#39;Node&#39;,&#39;GraphQl&#39;],<br>        yearsToServe: 2<br>    }<br>};<br><br>console.log(technologys.yearsToServe);    //2  <br>console.log(technologys.charged[1]);    //&quot;Node&quot;<br><br> <br>const person = {<br>    name: &#39;sAI&#39;,<br>    personObj: {<br>        technologys: [&#39;React&#39;, &#39;Node&#39;],<br>        yearsToServe: 2<br>    }<br>};<br><br>const { yearsToServe } = person.personObj;<br><br>console.log(yearsToServe);             //2          <br>console.log(person.personObj.technologys[1]);     //&quot;Node&quot;<br><br><br>const person = {<br>    name: &#39;sAI&#39;,<br>    personDetails: {<br>        Technology: [&#39;React&#39;, &#39;Node&#39;],<br>        yearsToServe: 25<br>    }<br>};<br><br>const { yearsToServe ,Technology} = person.personDetails;<br><br>console.log(yearsToServe);       //25      <br>console.log(Technology[1]);      //&quot;Node&quot;<br></pre><p><strong>12.What is the difference between ‘Pass by Value’ and ‘Pass by Reference’?<br>=&gt;</strong>In JavaScript, <strong>whenever a function is called,</strong> the <strong>arguments</strong> can be <strong>passed in two ways,</strong> either <strong>pass by value or pass by reference</strong>.<br>=&gt;<strong> Primitive datatypes</strong> such as<strong> string, number, boolean, null and undefined</strong> are passed by value. <br>=&gt;<strong>Non -primitive datatypes</strong> such as <strong>object, arrays or functions</strong> are <strong>passed by reference.</strong> <br>=&gt;In <strong>Pass by value</strong>, parameters <strong>passed as an arguments creates their own copy</strong>. <br>=&gt;So <strong>any changes made</strong> inside the <strong>function</strong> are made to the <strong>copied</strong> <strong>value</strong> so it <strong>will not affect the original value</strong>.</p><pre>let x = 10;<br><br>function changeValue(val) {<br>    val = 20;<br>    console.log(&quot;Inside function:&quot;, val);  // 20<br>}<br><br>changeValue(x);<br>console.log(&quot;Outside function:&quot;, x);  // 10 (original value remains unchanged)</pre><p>=&gt;In <strong>Pass by reference</strong>, <strong>parameters passed as an arguments does not</strong> <strong>creates their own copy.</strong> <br>=&gt;so any <strong>changes</strong> made <strong>inside</strong> the <strong>function</strong> will <strong>affect the original value.</strong></p><pre>// Pass by reference example<br>let arr = [1, 2, 3];<br>174 Interview questions &amp; Answers 9<br>function addToArr(value) {<br> value.push(4);<br> console.log(value); // Output: [1, 2, 3, 4]<br>}<br>addToArr(arr);<br>console.log(arr); // Output: [1, 2, 3, 4]</pre><p><strong>13.What is Map?</strong></p><p>=&gt;Map <strong>transforms each element</strong> of an <strong>array</strong> and <strong>creates a new array</strong> which <strong>contains the transformed elements.</strong></p><pre>**Syntax**<br><br>const newArray = oldArray.map((currentValue, index, array)=&gt;{<br>    // Do stuff with currentValue<br>})<br><br>========Best One=====<br>const mathScores = [39, 50, 45, 41, 50];<br>  <br>mathScores.map((currentValue, index, array) =&gt; {<br>    console.log(&#39;Current value:&#39; + currentValue);<br>    console.log(&#39;Index:&#39; + index);<br>    console.log(&#39;Array:&#39; + array);<br>    return currentValue;<br>})<br><br>O/P:<br>&quot;Current value:39&quot;<br>&quot;Index:0&quot;<br>&quot;Array:39,50,45,41,50&quot;<br>...<br>&quot;Current value:50&quot;<br>&quot;Index:4&quot;<br>&quot;Array:39,50,45,41,50&quot;<br><br><br>//for loop<br><br>const mathScores = [39, 50, 45, 41, 50]; <br>let newScores = [];<br>  <br>for (let i = 0; i &lt; mathScores.length; i++) {<br>    newScores.push(mathScores[i] + 5);<br>}<br><br>console.log(newScores); // [44,55,50,46,55]<br><br><br>const codes = [101, 201, 301, 303, 202]; <br>let mathCodes = codes.map((code)=&gt;{<br>    return `mth${code}`;<br>});<br>  <br>console.log(mathCodes); //[&quot;mth101&quot;,&quot;mth201&quot;,&quot;mth301&quot;,&quot;mth303&quot;,&quot;mth202&quot;]<br><br>const names = [&quot;Bilbo&quot;, &quot;Gandalf&quot;, &quot;Nazgul&quot;];<br>let lengths = names.map((name) =&gt; name.length);<br>console.log(lengths); // [5,7,6]<br><br>//With array of Object<br>const students = [<br>    {firstName : &quot;SaiKiran&quot;, lastName: &quot;Manchala&quot;},<br>    {firstName : &quot;Shiva&quot;, lastName: &quot;Manchala&quot;},<br>    {firstName : &quot;Ravali&quot;, lastName: &quot;Manchala&quot;}<br>];<br>  <br>let studentsNames = students.map(student =&gt; {<br>      return `${student.firstName} ${student.lastName}`;<br>})<br>  <br>console.log(studentsNames); <br><br>O/P: [&quot;SaiKiran Manchala&quot;, &quot;Shiva Manchala&quot;, &quot;Ravali Manchala&quot;]</pre><pre>Map with Filter:<br><br>const mathStudents = [<br>  {<br>    name: &quot;Sai&quot;,<br>    score: 60,<br>    enrollmentYear: 2019,<br>  },<br>  {<br>    name: &quot;Shiva&quot;,<br>    score: 40,<br>    enrollmentYear: 2020,<br>  },<br>  {<br>    name: &quot;Malleshwari&quot;,<br>    score: 43,<br>    enrollmentYear: 2019,<br>  },<br>  {<br>    name: &quot;Devaiah&quot;,<br>    score: 20,<br>    enrollmentYear: 2019,<br>  },<br>  {<br>    name: &quot;Ravalika&quot;,<br>    score: 80,<br>    enrollmentYear: 2017,<br>  },<br>]<br><br>const data = mathStudents<br>  .filter((student) =&gt; student.enrollmentYear &lt; 2020)<br>  .map((student) =&gt; {<br>    if (student.score &gt; 40) {<br>      return student.name + &quot;: Passing&quot;<br>    } else return student.name + &quot;: not passing&quot;<br>  })<br><br>console.log(data)<br><br>O/P:<br> [&quot;Sai: Passing&quot;, &quot;Malleshwari: Passing&quot;, &quot;Devaiah: not passing&quot;, &quot;Ravalika: Passing&quot;]</pre><p><strong>14.What is Filter?</strong></p><p>=&gt;Filter will <strong>creates a new array</strong> with <strong>only</strong> <strong>those</strong> elements which <strong>satisfies the specified condition.</strong></p><pre>*Syntax*<br>const filteredArray = oldArray.filter(callbackFn(element, index, array), context)<br><br><br>const numbers = [20, 40, 17, 99, 59, 77];<br>const filteredNumbers = numbers.filter((number) =&gt; {<br>    return number &gt; 20;<br>});<br>  <br>console.log(filteredNumbers); // [40,99,59,77]<br><br></pre><pre>*Array Parameters*<br><br>const competitors = [&quot;John&quot;, &quot;Doe&quot;, &quot;Stephen&quot;, &quot;Matt&quot;, &quot;Abigail&quot;, &quot;Susu&quot;];<br>  <br>function selectWinners(name, index, array) {<br>   <br>    if (array.length &gt; 3 &amp;&amp; name.includes(&#39;a&#39;)) {<br>        return true;<br>    } else {<br>      return false;<br>    }<br>}<br>  <br>let lselectLoosers = competitors.filter((name, index, array) =&gt;<br>    selectWinners(name, index, array)<br>);<br><br>console.log(lselectLoosers); // [&quot;Matt&quot;, &quot;Abigail&quot;, &quot;Susu&quot;]<br><br></pre><pre>//Object with filter()<br><br>const menu = [<br>    {<br>        name: &quot;buttermilk pancakes&quot;,<br>        price: 15.99<br>    },<br>    {<br>        name: &quot;diner double&quot;,<br>        price: 13.99<br>    },<br>    {<br>        name: &quot;godzilla milkshake&quot;,<br>        price: 6.99<br>    },<br>    {<br>        name: &quot;country delight&quot;,<br>        price: 20.99<br>    },<br>    {<br>        name: &quot;egg attack&quot;,<br>        price: 22.99<br>    }<br>];<br>  <br>let priceRange = {<br>    lower: 15,<br>    upper: 25<br>};<br><br>let filteredMenu = menu.filter(function (menu) {<br>    return menu.price &gt;= this.lower &amp;&amp; menu.price &lt;= this.upper;<br>}, priceRange);<br>  <br>console.log(filteredMenu);<br><br>O/P: <br>[{<br>  name: &quot;buttermilk pancakes&quot;,<br>  price: 15.99<br>}, {<br>  name: &quot;country delight&quot;,<br>  price: 20.99<br>}, {<br>  name: &quot;egg attack&quot;,<br>  price: 22.99<br>}]</pre><pre>*Array of Objects by Value*<br><br>const students = [<br>    { firstName: &quot;John&quot;, lastName: &quot;Doe&quot;, graduationYear : 2022 },<br>    { firstName: &quot;Stephen&quot;, lastName: &quot;Matt&quot;, graduationYear : 2023 },<br>    { firstName: &quot;Abigail&quot;, lastName: &quot;Susu&quot;, graduationYear : 2022 }<br>];<br><br>const currentYear = new Date().getFullYear();<br><br>let graduatingStudents = students.filter((element) =&gt; {<br>    if (element.graduationYear === currentYear) {<br>        return element;<br>    }<br>});<br>  <br>console.log(graduatingStudents);<br><br>O/P:<br>[<br>    {<br>        firstName:&quot;John&quot;,<br>        lastName:&quot;Doe&quot;,<br>        graduationYear:2022<br>    },<br>    {<br>        firstName:&quot;Abigail&quot;,<br>        lastName:&quot;Susu&quot;,<br>        graduationYear:2022<br>    }<br>]</pre><h4>Filtering Prime Numbers Using Array Filter In JavaScript:</h4><pre>const myArray = [-7, -5, -2, 2, 1, 3, 12, 14, 13, 15, 70, 17, 33, 25, 27, 30, 97];<br>      <br>const primeNumbers = myArray.filter((element) =&gt; {<br>    for (let i = 2; element &gt; i; i++) {<br>        if (element % i === 0) {<br>          return false;<br>        }<br>    }<br>    return element &gt; 1;<br>});<br>  <br>console.log(primeNumbers); // [2, 3, 13, 17, 97]<br><br>OR<br><br>const numbers = [-7, -5, -2, 2, 1, 3, 12, 14, 13, 15, 70, 17, 33, 25, 27, 30, 97];<br><br>function findPrimeNumbers(element) {<br>    for (let i = 2; element &gt; i; i++) {<br>        if (element % i === 0) {<br>          return false;<br>        }<br>    }<br>    return element &gt; 1;<br>}<br><br>console.log(numbers.filter(findPrimeNumbers)); // [2, 3, 13, 17, 97] </pre><pre> const menu = [<br>    {<br>      name: &quot;buttermilk pancakes&quot;,<br>      category: &quot;breakfast&quot;,<br>      price: 15.99,<br>      status: &quot;available&quot;<br>    },<br>    {<br>      name: &quot;diner double&quot;,<br>      category: &quot;lunch&quot;,<br>      price: 13.99,<br>      status: &quot;available&quot;<br>    },<br>    {<br>      name: &quot;godzilla milkshake&quot;,<br>      category: &quot;shakes&quot;,<br>      price: 6.99,<br>      status: &quot;available&quot;<br>    },<br>    {<br>      name: &quot;country delight&quot;,<br>      category: &quot;breakfast&quot;,<br>      price: 20.99,<br>      status: &quot;86&quot;<br>    },<br>    {<br>      name: &quot;egg attack&quot;,<br>      category: &quot;lunch&quot;,<br>      price: 22.99,<br>      status: &quot;available&quot;<br>    }<br>  ];<br><br>const delight = menu.find((menu) =&gt; menu.name === &quot;country delight&quot;);<br><br>if (!delight.status === &quot;86&quot;) {<br>    console.log(&#39;Available!&#39;);<br>} else {<br>    console.log(&#39;Sorry, the item is not available :(&#39;);<br>}<br><br>O/P: &quot;Sorry, the item is not available :(&quot;<br><br><br>FILTER WITH INDEXOF<br><br>let sciCourses = [&quot;Mth101&quot;, &quot;Chm201&quot;, &quot;Bio301&quot;, &quot;Mth203&quot;, &quot;Mth205&quot;];<br>function checkCourses(courseArray, searchText) {<br>    return courseArray.filter(function (item) {<br>        return item.toLowerCase().indexOf(searchText.toLowerCase()) !== -1;<br>    });<br>}<br>console.log(checkCourses(sciCourses, &quot;mth&quot;)); // [&quot;Mth101&quot;, &quot;Mth203&quot;, &quot;Mth205&quot;]</pre><p><strong>15.what is for-in and for-of and ForEach, Reduce?</strong></p><p><strong>**for-in:<br></strong>=&gt;The for-of statement <strong>executes</strong> a <strong>loop</strong> that <strong>operates on a sequence</strong> of <strong>Keys<br>**for-of:<br></strong>=&gt;The for-of statement <strong>executes</strong> a <strong>loop</strong> that <strong>operates on a sequence</strong> of <strong>values<br>=&gt;</strong>Examples of iterable <strong>objects are array, string, nodelists etc. (for of on object returns error)</strong></p><pre>const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br><br>for (const element of array1) {<br>  console.log(element);<br>} <br><br>O/P:<br>&quot;a&quot;<br>&quot;b&quot;<br>&quot;c&quot;<br><br> const array1 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br><br>for (const element in array1) {<br>  console.log(element);<br>} <br>O/P:<br>&quot;0&quot;<br>&quot;1&quot;<br>&quot;2&quot;<br><br><br>with object:<br><br>var person = {<br>    firstName: &#39;John&#39;,<br>    lastName: &#39;Doe&#39;,<br>    ssn: &#39;299-24-2351&#39;<br>};<br><br>for(var prop in person) {<br>    console.log(prop);<br>}<br>O/P:<br>&quot;firstName&quot;<br>&quot;lastName&quot;<br>&quot;ssn&quot;<br><br></pre><p><strong>ForEach:<br></strong>=&gt;The forEach() method calls a <strong>function and iterates over the elements of an array.</strong> The forEach() method can also be used on Maps and Sets.<br>=&gt;forEach method does not return a new array.</p><pre>const ages = [20, 28, 19, 56];<br>const newAges = [];<br><br>ages.forEach(function (age) {<br>    newAges.push(age + 5);<br>});<br><br>console.log(newAges); <br>// Output: [25, 33, 24, 61]</pre><p><strong>Reduce:<br>=&gt;</strong>reduce() method is used to <strong>process and accumulate values in an array,</strong> <strong>ultimately reducing them to a single value.<br>=&gt;</strong> It is used for a variety of <strong>tasks</strong>, such as <strong>calculating sums,</strong> <strong>finding</strong> <strong>maximum</strong> or <strong>minimum</strong> values, <strong>concatenating strings, and more.</strong></p><pre>const numbers = [1, 2, 3, 4, 5];<br>const sum = numbers.reduce((accumulator, currentValue) =&gt; accumulator + currentValue, 0);<br><br>console.log(sum); // Output: 15 (1 + 2 + 3 + 4 + 5)</pre><pre>const foodItems = [<br>  { id: 1, name: &#39;Pizza&#39;, price: 10, selected: true },<br>  { id: 2, name: &#39;Burger&#39;, price: 5, selected: true },<br>  { id: 3, name: &#39;Salad&#39;, price: 8, selected: false },<br>  { id: 4, name: &#39;Pasta&#39;, price: 10, selected: true },<br>  { id: 5, name: &#39;Sushi&#39;, price: 8, selected: false }<br>];<br><br>const selectedFoods = foodItems.filter(item =&gt; item.selected);<br>const totalCost = selectedFoods.reduce((sum, item) =&gt; {<br>  return sum + item.price;<br>}, 0);<br><br>console.log(selectedFoods);<br>console.log(`Total Cost of Selected Products: $${totalCost}`);<br><br>// Output:<br>// [<br>//   { id: 1, name: &#39;Pizza&#39;, price: 10, selected: true },<br>//   { id: 2, name: &#39;Burger&#39;, price: 5, selected: true },<br>//   { id: 4, name: &#39;Pasta&#39;, price: 10, selected: true }<br>// ]<br>// Total Cost of Selected Products: $25</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bda76b291f3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NodeJS_2024]]></title>
            <link>https://medium.com/@saikiranmanchala2000/nodejs-2024-0c695bcdb5d4?source=rss-b61070921186------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c695bcdb5d4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[sai_2kiran_4]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 12:40:43 GMT</pubDate>
            <atom:updated>2024-10-07T06:19:03.680Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*illqx2nONH9PbVX-" /><figcaption>NodeJS</figcaption></figure><p><strong>1.What is Node.js and why is it used?</strong></p><p>=&gt;Node.js is a <strong>powerful, open-source, server-side runtime</strong> environment <strong>built on Chrome’s V8 JavaScript engine.</strong><br>=&gt;It enables developers to use<strong> JavaScript to write server-side code</strong>.<br>=&gt;Node.js allows developers to use <strong>JavaScript both on the client-side and server-side , Providing unified Language and ecosystem.</strong><br>=&gt;Node.js is particularly known for its <strong>non-blocking</strong>, <strong>event-driven</strong>(means that the <strong>system</strong> responds to <strong>events</strong> (like user <strong>actions</strong> or <strong>network</strong> <strong>requests</strong>) and <strong>processes</strong> them <strong>asynchronously</strong>, allowing the <strong>application</strong> to <strong>handle</strong> <strong>multiple tasks </strong>concurrently <strong>without blocking</strong> other <strong>operations</strong>) architecture.<br>=&gt;This makes Node.js <strong>highly</strong> <strong>efficient</strong> and suitable for <strong>building</strong> <strong>scalable</strong> <strong>network</strong> <strong>applications</strong>, such as <strong>real-time chat applications, online gaming,</strong> and <strong>APIs</strong> that need to <strong>handle</strong> <strong>many</strong> <strong>connections</strong> <strong>simultaneously</strong>.<br>=&gt;One of the <strong>standout</strong> <strong>features</strong> of Node.js is its <strong>package</strong> <strong>manager</strong>, <strong>npm.<br>which provides access to a vast ecosystem of libraries and packages that can significantly accelerate development.<br></strong> =&gt;Its <strong>asynchronous</strong> <strong>nature</strong> and <strong>event loop model</strong> make it ideal for <strong>I/O-heavy</strong> <strong>tasks</strong>, such as <strong>reading</strong> <strong>files</strong>, <strong>querying</strong> <strong>databases</strong>, or <strong>making</strong> <strong>network</strong> <strong>requests</strong>, as it <strong>can handle these operations without blocking other tasks.</strong></p><p><strong>2.What are the main features of Node.js?</strong></p><p><strong>1.Non-blocking, Asynchronous I/O:</strong> <br>=&gt;One of the <strong>core strengths of Node.js</strong> is its <strong>non-blocking, asynchronous nature.<br>=&gt;</strong>This means it can handle <strong>multiple tasks at once</strong> without <strong>waiting</strong> for <strong>one</strong> to <strong>complete</strong> before <strong>moving</strong> on to the <strong>next</strong>.<br>=&gt;If it makes a<strong> database request</strong>, it <strong>won’t</strong> <strong>just</strong> sit <strong>idle</strong> until the <strong>response</strong> comes back.<br>=&gt; Instead, it’ll keep <strong>working</strong> on <strong>other tasks,</strong> and once the <strong>data</strong> is <strong>ready</strong>, it’ll <strong>come</strong> <strong>back to process it.<br>2.Single-threaded Event Loop: </strong><br>=&gt;<strong>Node.js runs on a single thread,</strong> <strong>unlike</strong> <strong>many other platforms</strong> that use <strong>multiple threads to handle tasks.</strong> <br>=&gt;It <strong>achieves</strong> <strong>high</strong> <strong>performance</strong> by <strong>using</strong> an <strong>event loop.<br></strong> The <strong>event</strong> <strong>loop</strong> <strong>constantly</strong> <strong>checks</strong> for <strong>tasks</strong> in the <strong>queue</strong> and <strong>processes</strong> <strong>them</strong> <strong>efficiently</strong>, making it <strong>highly</strong> <strong>scalable</strong> for <strong>I/O-heavy applications.<br>3.V8 Engine:<br>=&gt;</strong>Node.js runs on <strong>Google’s V8 JavaScript engine</strong>, the same <strong>engine used in Chrome.<br>=&gt;</strong>V8 is known for its <strong>speed and efficiency in executing JavaScript</strong>. <br>It takes <strong>JavaScript code </strong>and <strong>compiles</strong> it into <strong>machine</strong> <strong>code</strong> that your <strong>computer</strong> <strong>understands</strong>, <strong>leading</strong> to fast <strong>performance</strong>.<br><strong>**NPM (Node Package Manager):<br>=&gt;</strong>Node.js comes with <strong>NPM</strong>, a <strong>huge</strong> <strong>library</strong> of <strong>packages</strong> and <strong>modules.<br></strong>These <strong>packages</strong> are <strong>reusable</strong> <strong>pieces</strong> of code that other <strong>developers</strong> have created.<br>=&gt;It <strong>saves</strong> you a <strong>lot of time by allowing</strong> you to quickly <strong>integrate</strong> <strong>pre-built functionalities</strong> into your <strong>project</strong>.<br><strong>**Cross-platform Compatibility:<br>=&gt;</strong>Node.js works on various platforms like <strong>Windows, Linux, and macOS, allowing developers to build cross-platform applications</strong> without <strong>worrying</strong> about different operating systems.</p><p><strong>3.Explain the concept of Promises in Node.js.</strong></p><p><strong>=&gt;</strong>In Node.js, a <strong>Promise</strong> is an <strong>object</strong> that represents the <strong>eventual</strong> <strong>completion</strong> (or failure) of an <strong>asynchronous</strong> <strong>operation</strong> and its <strong>resulting</strong> <strong>value</strong>.<br>=&gt;<strong>Promises</strong> provide a more <strong>powerful</strong> and <strong>flexible</strong> way to <strong>handle</strong> <strong>asynchronous operations compared to traditional callbacks.<br>=&gt;We can </strong>write <strong>asynchronous</strong> <strong>code</strong> in a <strong>more</strong> <strong>synchronous</strong> <strong>manner</strong>, <strong>improving</strong> <strong>readability</strong> and <strong>maintainability</strong>.<br><strong>=&gt;A Promise has three states:</strong></p><p>1. <strong>Pending</strong>: The <strong>initial</strong> <strong>state</strong> of the <strong>Promise</strong>, before the <strong>asynchronous</strong> <strong>operation</strong> has <strong>completed</strong>.</p><p>2. <strong>Fulfilled</strong>: The state when the <strong>asynchronous</strong> <strong>operation</strong> <strong>completes</strong> <strong>successfully</strong>, and the <strong>Promise</strong> is <strong>resolved</strong> with a <strong>value</strong>.</p><p>3. <strong>Rejected</strong>: The state when the <strong>asynchronous</strong> operation <strong>fails</strong>, and the Promise is <strong>rejected</strong> with a <strong>reason</strong> (<strong>error</strong>).<br><strong>**Promises offer two main methods to handle the results of the asynchronous operation:<br>.then(): </strong>Used to define what <strong>should</strong> <strong>happen</strong> when the <strong>Promise</strong> is <strong>fulfilled</strong>.<br><strong>.catch(): </strong>Used to define what <strong>should</strong> <strong>happen</strong> when the <strong>Promise</strong> is <strong>rejected</strong>.</p><p><strong>4.What is the difference between synchronous and asynchronous functions in Node.js?<br>=&gt;</strong>In Node.js, <strong>synchronous functions</strong> are executed in a <strong>strict sequence,</strong> meaning <strong>each task must complete before the next one begins. <br>=&gt;</strong>If a function, like <strong>reading</strong> a <strong>large file</strong>, takes a<strong> long time to process</strong>, it <strong>blocks the entire application</strong>, causing other operations to wait and potentially <strong>slowing down performance.</strong></p><pre>console.log(&quot;Task 1: Start&quot;);<br><br>// This loop takes time and blocks the code execution<br>for (let i = 0; i &lt; 5; i++) {<br>    console.log(&quot;Task 2: Processing &quot; + i);<br>}<br><br>console.log(&quot;Task 3: End&quot;);<br><br>O/P:<br>Task 1: Start<br>Task 2: Processing 0<br>Task 2: Processing 1<br>Task 2: Processing 2<br>Task 2: Processing 3<br>Task 2: Processing 4<br>Task 3: End</pre><p><strong>=&gt;Asynchronous functions </strong>allow <strong>multiple operations to run at the same time without waiting for each one to finish.</strong> <br>=&gt;This approach <strong>uses callbacks, promises, or async/await</strong> to handle<strong> long-running tasks (such as network requests or database queries) without freezing the application.</strong> <br>=&gt;<strong>Asynchronous programming is essential in Node.js</strong> to utilize its <strong>non-blocking, event-driven architecture, which helps manage many concurrent operations efficiently.</strong></p><pre>console.log(&quot;Task 1: Start&quot;);<br><br>setTimeout(() =&gt; {<br>    console.log(&quot;Task 2: Asynchronous Operation&quot;);<br>}, 2000);  // Simulate async operation with a 2 second delay<br><br>console.log(&quot;Task 3: End&quot;);<br><br>O/P:<br>Task 1: Start<br>Task 3: End<br>Task 2: Asynchronous Operation  (After 2 seconds)</pre><p><strong>5.What is the purpose of the `async` and `await` keywords in Node.js?</strong></p><p>=&gt;The <strong>async and await keywords in Node.js</strong> are <strong>used</strong> to simplify working with <strong>asynchronous operations.<br>=&gt;</strong>In JavaScript, <strong>many functions</strong> like <strong>network requests</strong> or <strong>file</strong> <strong>operations</strong> are <strong>asynchronous</strong>, meaning <strong>they don’t block the main thread</strong> while <strong>waiting</strong> for a <strong>response.<br>=&gt;T</strong>his was <strong>handled using callbacks or promises</strong>, which could sometimes <strong>result</strong> in <strong>complex</strong> and <strong>less readable code,</strong> especially when <strong>dealing</strong> with <strong>multiple asynchronous actions.<br>**</strong>The <strong>async keyword</strong> is used to <strong>declare a function</strong> that <strong>returns a promise</strong>.<br>**<strong>Inside an async function</strong>, the<strong> await keyword </strong>can be used to <strong>pause the execution</strong> of the <strong>code</strong> until the <strong>promise</strong> is <strong>resolved</strong> or <strong>rejected</strong>.<br>=&gt;If the <strong>promise resolves,</strong> the <strong>result is returned;</strong> if it <strong>rejects</strong>, the <strong>error</strong> can be <strong>caught</strong> <strong>using</strong> a <strong>try-catch block.</strong></p><pre>async function fetchData() {<br> try {<br>  const data = await getDataFromAPI();<br>  console.log(data);<br> } catch (error) {<br>  console.error(error);<br> }<br>}<br>In this example, the await keyword ensures that the code execution waits for the getDataFromAPI() function to complete before moving forward.</pre><pre><br>function fetchData() {<br>    return new Promise((resolve, reject) =&gt; {<br>        setTimeout(() =&gt; {<br>            resolve(&quot;Data fetched from server!&quot;);<br>        }, 2000);  // 2-second delay<br>    });<br>}<br><br>// Async function<br>async function getData() {<br>    console.log(&quot;Fetching data...&quot;);<br><br>    // Await pauses the execution until fetchData() resolves<br>    let result = await fetchData();<br><br>    // Code below await runs after fetchData() completes<br>    console.log(result);  <br>    console.log(&quot;Done&quot;);<br>}<br><br>// Call the async function<br>getData();<br><br>console.log(&quot;This runs while waiting for data...&quot;);  // Executes immediately<br><br>O/P:<br>Fetching data...<br>This runs while waiting for data...<br>Data fetched from server!   (after 2 seconds)<br>Done</pre><p><strong>Reference:</strong> <a href="https://medium.com/@saikiranmanchala2000/api-fetching-in-react-913e2980ccef">https://medium.com/@saikiranmanchala2000/api-fetching-in-react-913e2980ccef</a></p><p><strong>6.What is a callback function in Node.js?</strong></p><p>=&gt;A callback function in Node.js is a <strong>function passed</strong> as an <strong>argument</strong> to <strong>another</strong> <strong>function</strong>, which is then <strong>executed</strong> <strong>after</strong> the <strong>completion</strong> of the <strong>task</strong>.<br>=&gt;This approach is <strong>fundamental</strong> in <strong>handling</strong> <strong>asynchronous</strong> <strong>operations</strong>, such as <strong>reading files, making API requests, or interacting with databases.<br>=&gt;</strong>In Node.js, <strong>callbacks</strong> are a <strong>key part of non-blocking I/O,</strong> allowing the <strong>system</strong> to <strong>move</strong> on to <strong>other tasks</strong> while <strong>waiting</strong> for the <strong>completion</strong> of an <strong>operation</strong>.</p><pre>// Function that accepts a callback function as an argument<br>function greet(name, callback) {<br>    console.log(&quot;Hello, &quot; + name);<br>    <br>    // Execute the callback function<br>    callback();<br>}<br><br>// Callback function to be passed<br>function sayGoodbye() {<br>    console.log(&quot;Goodbye!&quot;);<br>}<br><br>// Call the greet function and pass sayGoodbye as a callback<br>greet(&quot;Sai&quot;, sayGoodbye);<br><br>O/P:<br>Hello, Sai<br>Goodbye!</pre><p><strong>**Why Call callback() in greet() ?</strong> <br>=&gt;We want to perform another task. That task is not defined in greet() but is passed as a callback function (sayGoodbye in this case).<br>=&gt; By calling callback(), we&#39;re allowing the greet() function to execute the extra task defined in the callback.</p><p><strong>7.What is the purpose of the `require` function in Node.js?</strong></p><p>=&gt;The <strong>require</strong> function is <strong>used</strong> to <strong>include</strong> <strong>external modules in your Node.js</strong> application.</p><p><strong>**These modules can be:<br>=&gt;Built-in modules</strong> like <strong>fs</strong> (file system) or <strong>http</strong><br>=&gt;<strong>Third-party modules</strong> that are <strong>installed</strong> via <strong>npm</strong> (Node Package Manager)<br>=&gt;<strong>Custom</strong> <strong>modules</strong> that you <strong>create</strong> <strong>within</strong> your <strong>project.</strong></p><p><strong>=&gt;</strong>When you <strong>use require, Node.js</strong> will <strong>search</strong> for the <strong>module</strong>, <strong>load</strong> <strong>it</strong>, and <strong>return</strong> its <strong>exports</strong>, making its <strong>functionality</strong> <strong>available</strong> for u<strong>se in the file</strong> that <strong>required</strong> it.</p><pre><br>// Requiring a built-in module<br>const fs = require(&#39;fs&#39;); // file system module<br><br>// Requiring a third-party module<br>const express = require(&#39;express&#39;); // express framework<br><br>// Requiring a custom module<br>const myModule = require(&#39;./myModule&#39;); // relative path to custom module</pre><p><strong>8.What is the Difference between require and import?</strong></p><p><strong>**require</strong>:<br>=&gt;This is part of Node.js <strong>CommonJS</strong> <strong>module system</strong>. <br>=&gt;It loads <strong>modules synchronously, </strong>and it is<strong> available in all versions of Node.js.</strong></p><p><strong>**import: <br>=&gt;</strong>This is part of<strong> ECMAScript (ES6)</strong> modules, which is a newer module system.<br>=&gt; It allows for <strong>asynchronous</strong> l<strong>oading of modules,</strong> and you <strong>need</strong> to <strong>enable</strong> it in <strong>Node.js by setting “type”: “module”</strong> in your <strong>package.json</strong> <strong>file</strong> or by using .<strong>mjs</strong> file <strong>extensions</strong>.</p><pre>const fs = require(&#39;fs&#39;); // CommonJS style<br>import fs from &#39;fs&#39;; // ES6 style</pre><p><strong>Key Differences:</strong></p><p><strong>1. Syntax:</strong> <strong>require</strong> uses a function syntax (`<strong>const module = require(‘module’)</strong>`), while <strong>import</strong> uses a declarative syntax (`<strong>import module from ‘module’</strong>`).</p><p><strong>2. Loading:</strong> <strong>require</strong> loads modules <strong>synchronously</strong> (<strong>blocking</strong>), whereas import can be used to load modules <strong>asynchronously</strong> (<strong>non-blocking</strong>).</p><p><strong>3. Usage: </strong>require is the <strong>default</strong> in Node.js (<strong>CommonJS</strong>), while import <strong>follows</strong> the <strong>ES6</strong> <strong>specification</strong> and is becoming more <strong>widely</strong> <strong>adopted</strong> in <strong>modern</strong> <strong>applications</strong>.</p><p><strong>When to Use require vs. import:<br>=&gt;</strong>If you’re working on <strong>legacy(old)</strong> <strong>Node.js projects</strong> or modules, you’ll <strong>typically</strong> use <strong>require</strong>.<br>=&gt;For <strong>modern</strong> <strong>applications</strong> that use <strong>ES6 and later,</strong> you may <strong>prefer</strong> <strong>import</strong> <strong>due to its cleaner syntax and potential for asynchronous loading.</strong></p><p><strong>9.Explain the concept of middleware in Express.js?</strong></p><p>=&gt;Middleware in Express.js <strong>refers</strong> to <strong>functions</strong> that have <strong>access</strong> to the <strong>request object (req), </strong>the <strong>response object (res)</strong>, and the <strong>next</strong> <strong>middleware</strong> <strong>function</strong> in the <strong>application’s request-response cycle</strong>.<br>=&gt;These <strong>functions</strong> can <strong>execute code,</strong> <strong>modify</strong> the <strong>request</strong> and <strong>response</strong> <strong>objects</strong>, end the r<strong>equest-response cycle,</strong> or call the<strong> next middleware in the stack</strong>.<br>=&gt; Middleware is like the <strong>backbone</strong> of any <strong>Express.js application</strong>, as it <strong>helps</strong> in <strong>handling</strong> <strong>tasks</strong> such as <strong>logging</strong>, <strong>authentication, error handling, or serving static files.</strong></p><pre>const express = require(&#39;express&#39;); <br>const app = express();<br><br>// A middleware that logs request details<br>app.use((req, res, next) =&gt; { <br>    console.log(`Request Method: ${req.method}, Request URL: ${req.url}`); <br>    next(); // Pass the request to the next middleware or route handler<br>});<br><br>// A middleware that checks if user is authenticated<br>app.use((req, res, next) =&gt; { <br>    const isAuthenticated = true; // Dummy authentication logic<br>    if (isAuthenticated) {<br>        next(); // Proceed if authenticated<br>    } else {<br>        res.status(401).send(&#39;Unauthorized&#39;); <br>    }<br>});<br><br>// Route handler<br>app.get(&#39;/&#39;, (req, res) =&gt; { <br>    res.send(&#39;Welcome to the home page!&#39;);<br>});<br><br>// Start the server<br>app.listen(3000, () =&gt; { <br>    console.log(&#39;Server is running on port 3000&#39;);<br>});</pre><p><strong>10.What is the difference B/W package.json and package-lock.json?</strong></p><p>=&gt;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c695bcdb5d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>