<?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"><channel><title><![CDATA[My Awesome Blogs]]></title><description><![CDATA[A small dive into my life :D]]></description><link>https://rayonbyte.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6ade01b035a25e3ed5acb0a0/c9573dc2-e00e-4186-a59e-731bb975413d.png</url><title>My Awesome Blogs</title><link>https://rayonbyte.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 04 Nov 2026 21:15:36 GMT</lastBuildDate><atom:link href="https://rayonbyte.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Looping Statements]]></title><description><![CDATA[Looping statements are used to execute the same block of code repeatedly as long as a specified condition is satisfied. Very often, when writing code, you…]]></description><link>https://rayonbyte.hashnode.dev/looping-statements</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/looping-statements</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Fri, 30 Oct 2026 15:41:35 GMT</pubDate><content:encoded><![CDATA[<p>Looping statements are used to execute the same block of code repeatedly as long as a specified condition is satisfied.</p>
<ul>
<li><strong>Repetition</strong> — Allow the same block of code to execute multiple times without rewriting it.</li>
<li><strong>Efficiency</strong> — Reduce code duplication.</li>
<li><strong>Processing data</strong> — Useful for iterating through arrays, lists, and other collections.</li>
<li><strong>Automation</strong> — Perform repetitive tasks automatically.</li>
</ul>
<h1>Types of Looping Statements</h1>
<p>Very often, when writing code, you want the same block of code to run repeatedly. Instead of writing several similar lines of code, you can use loops to perform these tasks.</p>
<h2>1️⃣ For loop</h2>
<p>The <code>for</code> loop is used when you know in advance how many times the code should execute.</p>
<pre><code class="language-js">// Syntax
for (initialisation; condition; increment/decrement) {
    // Code to be executed
}

// Example
for (var i = 1; i &lt;= 10; i++) {
    console.log(i);
}
</code></pre>
<p><strong>Components of a for loop:</strong></p>
<ul>
<li><strong>Initialisation</strong> — Initializes the loop variable.</li>
<li><strong>Condition</strong> — Determines whether the loop should continue.</li>
<li><strong>Increment/Decrement</strong> — Updates the loop variable after each iteration.</li>
</ul>
<h2>2️⃣ While loop</h2>
<p>The <code>while</code> loop executes a block of code repeatedly as long as the specified condition is true.</p>
<pre><code class="language-js">// Syntax
initialisation;

while (condition) {
    // Code to be executed
    // Update variable
}

// Example
var i = 0;

while (i &lt;= 10) {
    console.log(i);
    i = i + 1;
}
</code></pre>
<blockquote>
<p><strong>Note</strong>   </p>
<p>The condition is checked before executing the loop body. Therefore, the loop may not execute even once if the condition is initially false.</p>
</blockquote>
<h2>3️⃣ Do...while loop</h2>
<p>The <code>do...while</code> loop executes the code block at least once, even if the condition is false, because the condition is checked after executing the code.</p>
<pre><code class="language-js">// Syntax
initialisation;

do {
    // Code to be executed
    // Update variable
} while (condition);

// Example
var i = 0;

do {
    console.log(i);
    i = i + 1;
} while (i &lt;= 10);
</code></pre>
<blockquote>
<p><strong>Note</strong>  </p>
<p>Unlike the <code>while</code> loop, the <code>do...while</code> loop checks the condition after executing the code block.</p>
</blockquote>
<hr />
<h2>Quick Comparison</h2>
<table>
<thead>
<tr>
<th>Loop</th>
<th>Condition Check</th>
<th>Minimum Executions</th>
</tr>
</thead>
<tbody><tr>
<td>for</td>
<td>Before execution</td>
<td>0</td>
</tr>
<tr>
<td>while</td>
<td>Before execution</td>
<td>0</td>
</tr>
<tr>
<td>do...while</td>
<td>After execution</td>
<td>1</td>
</tr>
</tbody></table>
]]></content:encoded></item><item><title><![CDATA[Control Statements]]></title><description><![CDATA[Control statements are used to control the flow of execution of a program based on certain conditions. Very often, when writing code, you want to perform…]]></description><link>https://rayonbyte.hashnode.dev/control-statements</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/control-statements</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Fri, 30 Oct 2026 15:39:29 GMT</pubDate><content:encoded><![CDATA[<p>Control statements are used to control the flow of execution of a program based on certain conditions.</p>
<ul>
<li><strong>Decision-making</strong> — Programs can choose different actions based on input or situations (e.g., if a user is logged in, show the dashboard).</li>
<li><strong>Control program flow</strong> — They determine which block of code should execute.</li>
<li><strong>Handle different situations</strong> — They allow programs to respond differently depending on the conditions.</li>
</ul>
<h1>Conditional Statements</h1>
<p>Very often, when writing code, you want to perform different actions based on different decisions. You can use conditional statements to achieve this.</p>
<h2>1️⃣ If statement</h2>
<p>The <code>if</code> statement executes a block of code only if a specified condition is true.</p>
<pre><code class="language-js">// Syntax
if (condition) {
    // Code to be executed if condition is true
}

// Example
if (time &lt; 10) {
    document.write("&lt;b&gt;Good morning&lt;/b&gt;");
}
</code></pre>
<h2>2️⃣ If...else statement</h2>
<p>The <code>if...else</code> statement executes one block of code if the condition is true and another block if the condition is false.</p>
<pre><code class="language-js">// Syntax
if (condition) {
    // Code to be executed if condition is true
} else {
    // Code to be executed if condition is false
}

// Example
if (time &lt; 10) {
    document.write("Good morning!");
} else {
    document.write("Good day!");
}
</code></pre>
<h2>3️⃣ Switch statement</h2>
<p>The <code>switch</code> statement is used to select and execute one block of code from multiple possible options based on an expression.</p>
<pre><code class="language-js">// Syntax
switch (expression) {
    case label1:
        // Execute code block 1
        break;

    case label2:
        // Execute code block 2
        break;

    default:
        // Code to execute if no case matches
}
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="language-js">switch (theDay) {
    case 5:
        document.write("Finally Friday");
        break;

    case 6:
        document.write("Super Saturday");
        break;

    case 0:
        document.write("Sleepy Sunday");
        break;

    default:
        document.write("I'm looking forward to this weekend!");
}
</code></pre>
<blockquote>
<p><strong>Note</strong> </p>
<ul>
<li><code>case</code> specifies a possible value to match.</li>
<li><code>break</code> terminates the switch statement and prevents execution from continuing into the next case.</li>
<li><code>default</code> executes when none of the cases match.</li>
</ul>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Math Object]]></title><description><![CDATA[Math is a built-in JavaScript object that provides a collection of properties and methods related to mathematical operations. Examples: The Math.round()…]]></description><link>https://rayonbyte.hashnode.dev/math-object</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/math-object</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Fri, 30 Oct 2026 15:35:17 GMT</pubDate><content:encoded><![CDATA[<p><code>Math</code> is a built-in JavaScript object that provides a collection of properties and methods related to mathematical operations.</p>
<p><strong>Examples:</strong></p>
<pre><code class="language-js">console.log(Math.PI) // 3.141592653589793
console.log(Math.E)  // 2.718281828459045
</code></pre>
<h2>📐 Math Methods</h2>
<h3>1. round() method</h3>
<p>The <code>Math.round()</code> method rounds a decimal number to the nearest integer.</p>
<pre><code class="language-js">console.log(Math.round(3.4)) // 3
console.log(Math.round(3.7)) // 4
</code></pre>
<h3>2. floor() method</h3>
<p>The <code>Math.floor()</code> method rounds a number down to the greatest integer less than or equal to the given number.</p>
<pre><code class="language-js">console.log(Math.floor(3.9))  // 3
console.log(Math.floor(-3.2)) // -4
</code></pre>
<h3>3. ceil() method</h3>
<p>The <code>Math.ceil()</code> method rounds a number up to the smallest integer greater than or equal to the given number.</p>
<pre><code class="language-js">console.log(Math.ceil(3.22)) // 4
console.log(Math.ceil(3.8))  // 4
</code></pre>
<h3>4. trunc() method</h3>
<p>The <code>Math.trunc()</code> method removes all decimal places and keeps only the integer part of the number.</p>
<pre><code class="language-js">console.log(Math.trunc(3.88))  // 3
console.log(Math.trunc(-3.88)) // -3
</code></pre>
<h3>5. abs() method</h3>
<p>The <code>Math.abs()</code> method returns the absolute (non-negative) value of a number. It is similar to the modulus operation.</p>
<pre><code class="language-js">console.log(Math.abs(-2.03)) // 2.03
console.log(Math.abs(5))     // 5
</code></pre>
<h3>6. pow() and sqrt() methods</h3>
<ul>
<li><code>Math.pow()</code> returns a number raised to a specified power.</li>
<li><code>Math.sqrt()</code> returns the square root of a number.</li>
</ul>
<pre><code class="language-js">console.log(Math.pow(2, 3)) // 8

console.log(Math.sqrt(81)) // 9
</code></pre>
<h3>7. log() method</h3>
<p>The <code>Math.log()</code> method returns the natural logarithm of a number, that is, the logarithm to base <strong>e (approximately 2.718)</strong>.</p>
<pre><code class="language-js">console.log(Math.log(10)) // 2.302585...
</code></pre>
<h3>8. Trigonometric functions</h3>
<p>JavaScript provides trigonometric functions through the <code>Math</code> object.</p>
<pre><code class="language-js">console.log(Math.sin(0)) // 0

console.log(Math.cos(0)) // 1

console.log(Math.tan(0)) // 0
</code></pre>
<blockquote>
<p><strong>Note</strong> </p>
<p>Trigonometric functions accept angles in radians, not degrees.</p>
</blockquote>
<h3>9. sign() method</h3>
<p>The <code>Math.sign()</code> method returns:</p>
<ul>
<li><code>-1</code> for negative numbers.</li>
<li><code>1</code> for positive numbers.</li>
<li><code>0</code> for zero.</li>
</ul>
<pre><code class="language-js">console.log(Math.sign(-9)) // -1
console.log(Math.sign(0))  // 0
console.log(Math.sign(9))  // 1
</code></pre>
<hr />
<blockquote>
<p><strong>Note</strong></p>
<p>You can assign numbers to variables and pass those variables to Math methods instead of passing numbers directly.</p>
</blockquote>
<pre><code class="language-js">let num = 3.8;

console.log(Math.round(num)) // 4
console.log(Math.floor(num)) // 3
</code></pre>
<h2>Quick Revision Table</h2>
<table>
<thead>
<tr>
<th>Method</th>
<th>Purpose</th>
</tr>
</thead>
<tbody><tr>
<td><code>Math.round()</code></td>
<td>Rounds to nearest integer</td>
</tr>
<tr>
<td><code>Math.floor()</code></td>
<td>Rounds down</td>
</tr>
<tr>
<td><code>Math.ceil()</code></td>
<td>Rounds up</td>
</tr>
<tr>
<td><code>Math.trunc()</code></td>
<td>Removes decimal part</td>
</tr>
<tr>
<td><code>Math.abs()</code></td>
<td>Returns absolute value</td>
</tr>
<tr>
<td><code>Math.pow()</code></td>
<td>Calculates power</td>
</tr>
<tr>
<td><code>Math.sqrt()</code></td>
<td>Calculates square root</td>
</tr>
<tr>
<td><code>Math.log()</code></td>
<td>Returns natural logarithm</td>
</tr>
<tr>
<td><code>Math.sin()</code></td>
<td>Calculates sine</td>
</tr>
<tr>
<td><code>Math.cos()</code></td>
<td>Calculates cosine</td>
</tr>
<tr>
<td><code>Math.tan()</code></td>
<td>Calculates tangent</td>
</tr>
<tr>
<td><code>Math.sign()</code></td>
<td>Returns sign of a number</td>
</tr>
</tbody></table>
]]></content:encoded></item><item><title><![CDATA[Strings]]></title><description><![CDATA[A String is a sequence of characters used to store text data. Strings can be enclosed in "", '' or `` For creating a string, new String("Hello") is rarely…]]></description><link>https://rayonbyte.hashnode.dev/strings</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/strings</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 18:50:11 GMT</pubDate><content:encoded><![CDATA[<p>A String is a sequence of characters used to store text data.</p>
<pre><code class="language-js">let name = "Rohan";
let city = "Bangalore";
</code></pre>
<p>Strings can be enclosed in "", '' or ``</p>
<h2>👶 Creating strings</h2>
<p>For creating a string, <code>new String("Hello")</code> is rarely used, primitive and simple way is used to define and declare strings.</p>
<pre><code class="language-js">let message = "Hi";
</code></pre>
<h3>🔒 String Immutability</h3>
<p>Strings are immutable, meaning their characters cannot be changed directly after creation.</p>
<pre><code class="language-js">let str = "Hello";
str[0] = "Y";

console.log(str); // "Hello"
</code></pre>
<p>String methods return new strings instead of modifying the original string.</p>
<h2>📞 Accessing Characters</h2>
<p>Characters can be accessed using square bracket notation or the <code>at()</code> method. Indexing starts from <code>0</code>.</p>
<pre><code class="language-js">let str = "Hello";

console.log(str[0]);   // "H"
console.log(str.at(0));  // "H"
console.log(str.at(-1)); // "o" (last character)
</code></pre>
<blockquote>
<p><em>Note</em>  </p>
<p>Negative indices work with at(), but not with square bracket notation.</p>
</blockquote>
<h2>String properties</h2>
<p>length property</p>
<pre><code class="language-js">let str = "javascript is amazing";
console.log(str.length); // returns the length of the string including blank spaces.
</code></pre>
<h2>⚙️ String methods</h2>
<ol>
<li>ToUppercase() - to convert all characters into uppercase alphabets</li>
</ol>
<pre><code class="language-js">console.log("hi".toUpperCase()); // "HI"
</code></pre>
<ol start="2">
<li>toLowerCase() - to convert all characters into lowercase alphabets</li>
</ol>
<pre><code class="language-js">console.log("HI".toLowerCase()); // "hi"
</code></pre>
<ol start="3">
<li>trim methods</li>
</ol>
<pre><code class="language-js">console.log(" hi ".trim()); // "hi"
console.log(" hi ".trimStart()); // "hi "
console.log(" hi ".trimEnd()); // " hi"
</code></pre>
<ol start="4">
<li>includes() - returns true if the input string is a substring of the string</li>
</ol>
<pre><code class="language-js">console.log("Javascript".includes("Java")); // true
console.log("Javascript".includes("Python")); // fasle
</code></pre>
<ol start="5">
<li>startsWitn and endsWith methods</li>
</ol>
<pre><code class="language-js">console.log("Javascript".startsWith("Java")); // true
console.log("Javascript".startsWith("Python")); // fasle

console.log("Javascript".endsWith("script")); // true
console.log("Javascript".endsWith("lang")); // fasle
</code></pre>
<ol start="6">
<li>indexOf() and lastIndexOf() - return the first or last index of the substringin the string, or else reutrn -1 if not present</li>
</ol>
<pre><code class="language-js">console.log("java".indexOf("a")); // 1
console.log("java".lastIndexof("a")); // 3
</code></pre>
<ol start="7">
<li>slice() - used to extract part of the string</li>
</ol>
<pre><code class="language-js">console.log("Javascript".slice(4)); // from the 4th till last index --&gt; "script"
console.log("Javascript".slice(0,4)); // from 0th to 4 -1 = 3rd index --&gt; "Java"
console.log("Javascript".slice(-6)); // last 6 characters --&gt; "script"
</code></pre>
<ol start="8">
<li><code>substring()</code> - extracts a part of a string using start and end indices. The end index is excluded.</li>
</ol>
<pre><code class="language-js">console.log("Javascript".substring(0, 4)); // "Java"
console.log("Javascript".substring(4));    // "script"
</code></pre>
<blockquote>
<p><em>Note</em></p>
<p>Unlike slice(), substring() treats negative indices as 0 and swaps the arguments if the start index is greater than the end index.</p>
</blockquote>
<ol start="9">
<li>replace() and replaceAll() - used to substitute parts of the string with replacement</li>
</ol>
<pre><code class="language-js">console.log("ha ha ha".replace("ha", "hi"));    // "hi ha ha"
console.log("ha ha ha".replaceAll("ha", "hi")); // "hi hi hi"
</code></pre>
<ol start="10">
<li>split(<code>delimiter</code>) - used to convert string into and array</li>
</ol>
<pre><code class="language-js">console.log("apples,mangoes,bananas".split(",")); // ["apples","mangoes","bananas"]
</code></pre>
<ol start="11">
<li>concat() - to attach a string in the end</li>
</ol>
<pre><code class="language-js">console.log("Merry".concat(" and ", "James")); // "Merry and James"
</code></pre>
<ol start="12">
<li>repeat() - used to repeat a string for a number of times</li>
</ol>
<pre><code class="language-js">console.log("*".repeat(3)); // "***"
</code></pre>
<ol start="13">
<li>charAt() - returns the character at the index</li>
</ol>
<pre><code class="language-js">console.log("Javascript".charAt(2)); // "v"
</code></pre>
<ol start="14">
<li>charCodeAt()  - returns the ASCII value of the characte at the index</li>
</ol>
<pre><code class="language-js">console.log("A".charCodeAt(0)); // 65
</code></pre>
<ol start="15">
<li>padStart() and padEnd() - pad the string to the spefic length by contcatinating the given character to the start or the end</li>
</ol>
<pre><code class="language-js">console.log("5".padStart(3,"0")); // "005"
console.log("5".padEnd(3,"0")); // "500"
</code></pre>
<ol start="16">
<li>match() - to find substrings using regular expression</li>
</ol>
<pre><code class="language-js">console.log("abc123".match(/\d+/)); // "123"
</code></pre>
<ol start="17">
<li>search() - finds the index of the substring</li>
</ol>
<pre><code class="language-js">console.log("hello123".search(/\d/)); // 5
</code></pre>
<blockquote>
<p><em>Note</em>  </p>
<p><code>String("Hello")</code> returns a primitive string, whereas <code>new String("Hello")</code> creates a String object. Prefer primitive strings.</p>
<pre><code class="language-js">console.log(typeof String("Hello"));     // "string"
console.log(typeof new String("Hello")); // "object"
</code></pre>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Type Conversion and Coercion]]></title><description><![CDATA[Type conversion is the process of changing a value from one datatype to another. JavaScript provides built-in functions to convert values into different…]]></description><link>https://rayonbyte.hashnode.dev/type-conversion-and-coercion</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/type-conversion-and-coercion</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 18:33:09 GMT</pubDate><content:encoded><![CDATA[<p>Type conversion is the process of changing a value from one datatype to another.</p>
<ul>
<li><strong>Type Conversion:</strong> Explicitly converting a value to another datatype.</li>
<li><strong>Type Coercion:</strong> JavaScript automatically converts a value to another datatype during an operation.</li>
</ul>
<h2>🔄 Type Conversion</h2>
<p>JavaScript provides built-in functions to convert values into different datatypes.</p>
<h3>🔤 Convert to String</h3>
<p>Use <code>String()</code> or <code>.toString()</code> to convert a value into a string.</p>
<table>
<thead>
<tr>
<th>Example</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>String(123)</code></td>
<td><code>"123"</code></td>
</tr>
<tr>
<td><code>String(true)</code></td>
<td><code>"true"</code></td>
</tr>
<tr>
<td><code>String(null)</code></td>
<td><code>"null"</code></td>
</tr>
<tr>
<td><code>String(undefined)</code></td>
<td><code>"undefined"</code></td>
</tr>
<tr>
<td><code>String([1, 2, 3])</code></td>
<td><code>"1,2,3"</code></td>
</tr>
</tbody></table>
<pre><code class="language-js">let age = 20;

console.log(String(age)); // "20"
console.log(age.toString()); // "20"
</code></pre>
<blockquote>
<p><em>Note</em>  </p>
<p><code>null</code> and <code>undefined</code> cannot directly use <code>.toString()</code> because they don't have that method.</p>
</blockquote>
<h3>🔢 Convert to Number</h3>
<p>Use <code>Number()</code>, <code>parseInt()</code>, or <code>parseFloat()</code> to convert values into numbers.</p>
<table>
<thead>
<tr>
<th>Example</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>Number("123")</code></td>
<td><code>123</code></td>
</tr>
<tr>
<td><code>Number("12.5")</code></td>
<td><code>12.5</code></td>
</tr>
<tr>
<td><code>Number("")</code></td>
<td><code>0</code></td>
</tr>
<tr>
<td><code>Number("Hello")</code></td>
<td><code>NaN</code></td>
</tr>
<tr>
<td><code>Number(true)</code></td>
<td><code>1</code></td>
</tr>
<tr>
<td><code>Number(false)</code></td>
<td><code>0</code></td>
</tr>
<tr>
<td><code>Number(null)</code></td>
<td><code>0</code></td>
</tr>
<tr>
<td><code>Number(undefined)</code></td>
<td><code>NaN</code></td>
</tr>
</tbody></table>
<h4><code>parseInt()</code> vs <code>parseFloat()</code> vs <code>Number()</code></h4>
<pre><code class="language-js">Number("123abc");    // NaN
parseInt("123abc");  // 123
parseFloat("12.5px"); // 12.5
parseInt("12.9");    // 12
parseFloat("12.9");  // 12.9
</code></pre>
<ul>
<li><code>Number()</code> converts the entire value. Invalid numeric strings produce <code>NaN</code>.</li>
<li><code>parseInt()</code> extracts an integer from the beginning of a string.</li>
<li><code>parseFloat()</code> extracts a floating-point number from the beginning of a string.</li>
</ul>
<h3>✅ Convert to Boolean</h3>
<p>Use <code>Boolean()</code> to convert a value into <code>true</code> or <code>false</code>.</p>
<pre><code class="language-js">Boolean(1);         // true
Boolean(0);         // false
Boolean("Hello");   // true
Boolean("");        // false
Boolean(null);      // false
Boolean(undefined); // false
Boolean(NaN);       // false
Boolean([]);        // true
Boolean({});        // true
</code></pre>
<h3>🚦 Truthy and Falsy Values</h3>
<p>In JavaScript, every value is either truthy or falsy when evaluated in a Boolean context.</p>
<p><strong>Falsy values:</strong></p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td><code>false</code></td>
<td><code>Boolean(false)</code></td>
</tr>
<tr>
<td><code>0</code>, <code>-0</code></td>
<td><code>Boolean(0)</code></td>
</tr>
<tr>
<td><code>0n</code></td>
<td><code>Boolean(0n)</code></td>
</tr>
<tr>
<td><code>""</code></td>
<td><code>Boolean("")</code></td>
</tr>
<tr>
<td><code>null</code></td>
<td><code>Boolean(null)</code></td>
</tr>
<tr>
<td><code>undefined</code></td>
<td><code>Boolean(undefined)</code></td>
</tr>
<tr>
<td><code>NaN</code></td>
<td><code>Boolean(NaN)</code></td>
</tr>
</tbody></table>
<p>All other values are truthy, including <code>"0"</code>, <code>"false"</code>, <code>[]</code>, and <code>{}</code>.</p>
<pre><code class="language-js">if ("Hello") {
    console.log("Executed"); // Executed
}

if (0) {
    console.log("Not executed");
}
</code></pre>
<h2>🤖 Type Coercion</h2>
<p>Type coercion occurs when JavaScript automatically converts values to make an operation possible.</p>
<h3>➕ The <code>+</code> Operator</h3>
<p>The <code>+</code> operator performs either numeric addition or string concatenation.</p>
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
<th>Explanation</th>
</tr>
</thead>
<tbody><tr>
<td><code>5 + 2</code></td>
<td><code>7</code></td>
<td>Numeric addition</td>
</tr>
<tr>
<td><code>"5" + 2</code></td>
<td><code>"52"</code></td>
<td>String concatenation</td>
</tr>
<tr>
<td><code>5 + "2"</code></td>
<td><code>"52"</code></td>
<td>String concatenation</td>
</tr>
<tr>
<td><code>true + 1</code></td>
<td><code>2</code></td>
<td><code>true</code> converts to <code>1</code></td>
</tr>
<tr>
<td><code>false + 1</code></td>
<td><code>1</code></td>
<td><code>false</code> converts to <code>0</code></td>
</tr>
<tr>
<td><code>null + 1</code></td>
<td><code>1</code></td>
<td><code>null</code> converts to <code>0</code></td>
</tr>
<tr>
<td><code>undefined + 1</code></td>
<td><code>NaN</code></td>
<td><code>undefined</code> converts to <code>NaN</code></td>
</tr>
<tr>
<td><code>[] + 1</code></td>
<td><code>"1"</code></td>
<td><code>[]</code> converts to <code>""</code></td>
</tr>
<tr>
<td><code>[1, 2] + 3</code></td>
<td><code>"1,23"</code></td>
<td>Array converts to <code>"1,2"</code></td>
</tr>
</tbody></table>
<p><strong>General rule:</strong></p>
<ul>
<li>If string concatenation is triggered, JavaScript converts the operands to primitives and then to strings as needed.</li>
<li>Otherwise, JavaScript converts the operands to primitives and performs numeric addition.</li>
</ul>
<pre><code class="language-js">console.log("Age: " + 20); // "Age: 20"
console.log(10 + 20);      // 30
console.log(true + true); // 2
console.log([] + []);      // ""
</code></pre>
<h3>➖ Other Arithmetic Operators</h3>
<p>Operators such as <code>-</code>, <code>*</code>, <code>/</code>, and <code>%</code> generally convert operands to numbers.</p>
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>"5" - 2</code></td>
<td><code>3</code></td>
</tr>
<tr>
<td><code>"5" * 2</code></td>
<td><code>10</code></td>
</tr>
<tr>
<td><code>"10" / 2</code></td>
<td><code>5</code></td>
</tr>
<tr>
<td><code>"5" % 2</code></td>
<td><code>1</code></td>
</tr>
<tr>
<td><code>"Hello" - 2</code></td>
<td><code>NaN</code></td>
</tr>
</tbody></table>
<pre><code class="language-js">console.log("10" - 5); // 5
console.log("10" * 2); // 20
console.log("10" / 2); // 5
</code></pre>
<h3>⚖️ Comparison Coercion</h3>
<p>The <code>==</code> operator allows type coercion, whereas <code>===</code> compares without converting the operand types.</p>
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>5 == "5"</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>5 === "5"</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>0 == false</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>0 === false</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>null == undefined</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>null === undefined</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>"" == 0</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>"" === 0</code></td>
<td><code>false</code></td>
</tr>
</tbody></table>
<blockquote>
<p><em>Note</em>  </p>
<p>Prefer <code>===</code> and <code>!==</code> unless you specifically need the coercion behavior of loose equality.</p>
</blockquote>
<h3>🧠 Logical Operator Coercion</h3>
<p>Logical operators such as <code>&amp;&amp;</code> and <code>||</code> evaluate truthiness but return one of their operand values, not necessarily a Boolean.</p>
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td><code>"Hello" &amp;&amp; 5</code></td>
<td><code>5</code></td>
</tr>
<tr>
<td><code>0 &amp;&amp; 5</code></td>
<td><code>0</code></td>
</tr>
<tr>
<td>`""</td>
<td></td>
</tr>
<tr>
<td>`0</td>
<td></td>
</tr>
<tr>
<td><code>!0</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>!"Hello"</code></td>
<td><code>false</code></td>
</tr>
</tbody></table>
<ul>
<li><code>&amp;&amp;</code> returns the first falsy operand, or the last operand if all are truthy.</li>
<li><code>||</code> returns the first truthy operand, or the last operand if all are falsy.</li>
<li><code>!</code> converts the operand to a Boolean and negates it.</li>
</ul>
<h2>⚠️ Special Cases</h2>
<h3><code>typeof</code> and <code>NaN</code></h3>
<pre><code class="language-js">typeof NaN; // "number"
typeof null; // "object"
</code></pre>
<p><code>NaN</code> means "Not a Number", but its datatype is still <code>number</code>. The result of <code>typeof null</code> is a historical JavaScript behavior.</p>
<h3>Checking for <code>NaN</code></h3>
<pre><code class="language-js">console.log(NaN === NaN);       // false
console.log(Number.isNaN(NaN)); // true
console.log(Number.isNaN("Hi")); // false
</code></pre>
<p>Use <code>Number.isNaN()</code> to check whether a value is actually <code>NaN</code>.</p>
<h3>Implicit Conversion in Conditions</h3>
<pre><code class="language-js">let age = "18";

if (age &gt;= 18) {
    console.log("Eligible"); // Eligible
}
</code></pre>
<p>The comparison converts <code>"18"</code> to a number before comparing it with <code>18</code>.</p>
]]></content:encoded></item><item><title><![CDATA[Operators]]></title><description><![CDATA[Operators are symbols used to execute certian operations represented by it. Consider y = 5 Consider x = 10 y = 5 The + operator performs either addition or…]]></description><link>https://rayonbyte.hashnode.dev/operators</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/operators</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 16:53:25 GMT</pubDate><content:encoded><![CDATA[<p>Operators are symbols used to execute certian operations represented by it.</p>
<h2>🧮 Arithmetic operators</h2>
<p>Consider <code>y = 5</code> </p>
<table>
<thead>
<tr>
<th align="center">Operator</th>
<th align="center">Example</th>
<th align="center">Result</th>
<th align="center">Description</th>
</tr>
</thead>
<tbody><tr>
<td align="center">+</td>
<td align="center">x = y + 2</td>
<td align="center">7</td>
<td align="center">Addition</td>
</tr>
<tr>
<td align="center">-</td>
<td align="center">x = y - 2</td>
<td align="center">3</td>
<td align="center">Subtraction</td>
</tr>
<tr>
<td align="center">*</td>
<td align="center">x = y * 2</td>
<td align="center">10</td>
<td align="center">Multiplication</td>
</tr>
<tr>
<td align="center">/</td>
<td align="center">x = y / 2</td>
<td align="center">2.5</td>
<td align="center">Division</td>
</tr>
<tr>
<td align="center">%</td>
<td align="center">x = y % 2</td>
<td align="center">1</td>
<td align="center">Remainder (Modulo)</td>
</tr>
<tr>
<td align="center">**</td>
<td align="center">x = y ** 2</td>
<td align="center">25</td>
<td align="center">Exponentiation</td>
</tr>
<tr>
<td align="center">++</td>
<td align="center">x = ++y</td>
<td align="center">6</td>
<td align="center">Pre-increment</td>
</tr>
<tr>
<td align="center">--</td>
<td align="center">x = --y</td>
<td align="center">4</td>
<td align="center">Pre-decrement</td>
</tr>
</tbody></table>
<h2>🟰 Assignment operators</h2>
<p>Consider <code>x = 10 y = 5</code></p>
<table>
<thead>
<tr>
<th align="center">Operator</th>
<th align="center">Example</th>
<th align="center">Result</th>
<th align="center">Description</th>
</tr>
</thead>
<tbody><tr>
<td align="center">=</td>
<td align="center">x = y</td>
<td align="center">5</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">+=</td>
<td align="center">x += y</td>
<td align="center">15</td>
<td align="center">x=x+y</td>
</tr>
<tr>
<td align="center">-=</td>
<td align="center">x -= y</td>
<td align="center">5</td>
<td align="center">x=x-y</td>
</tr>
<tr>
<td align="center">*=</td>
<td align="center">x *= y</td>
<td align="center">50</td>
<td align="center">x=x*y</td>
</tr>
<tr>
<td align="center">/=</td>
<td align="center">x /= y</td>
<td align="center">2</td>
<td align="center">x=x/y</td>
</tr>
<tr>
<td align="center">%=</td>
<td align="center">x %= y</td>
<td align="center">0</td>
<td align="center">x=x%y</td>
</tr>
<tr>
<td align="center">**</td>
<td align="center">x **= y</td>
<td align="center">100000</td>
<td align="center">x = x ** y</td>
</tr>
</tbody></table>
<h3>➕ operator logic</h3>
<p>The <code>+</code> operator performs either addition or string concatenation.</p>
<ul>
<li>If string concatenation is triggered, values are converted to strings.</li>
<li>Otherwise, values are converted to primitives, then numeric addition is performed.</li>
<li>Objects and arrays are converted to primitive values when necessary.</li>
</ul>
<pre><code class="language-js">txt1="What a very "; 
txt2="nice day"; 
txt3=txt1+txt2; // What a very nice day
</code></pre>
<p>With mixed data types, the + operator causes JavaScript to run through a set sequence of <strong>type conversions</strong>  </p>
<blockquote>
<p>IF String is present -&gt; Convert into String and concatenate<br />IF NOT<br />IF Object/Array is present -&gt; Convert into primitive<br />If NOT<br />Convert into Numeric type and add<br />If NOT possible to even convert into number<br />return NaN</p>
</blockquote>
<h4>Illustraction of + operator</h4>
<pre><code class="language-js">[] + 1          // "1"
"Hi" + 1        // "Hi1"
true + false    // 1
true + "1"      // "true1"
true + 1        // 2
null + 1        // 1
undefined + 1   // NaN
</code></pre>
<blockquote>
<p><em>Note</em></p>
<p>Other arithmetic operators try to convert all other types into numeric.<br />Ex: "5" - 5 --&gt; 0</p>
</blockquote>
<h2>⚖️Comparison operators</h2>
<table>
<thead>
<tr>
<th align="center">Operator</th>
<th align="center">Description</th>
<th align="center">Example</th>
<th align="center">Result</th>
</tr>
</thead>
<tbody><tr>
<td align="center">==</td>
<td align="center">equal to</td>
<td align="center">true == 1</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">===</td>
<td align="center">exactly equal to</td>
<td align="center">true === 1</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">!=</td>
<td align="center">not equal to</td>
<td align="center">true != 1</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">!==</td>
<td align="center">Strictly not equal to</td>
<td align="center">true !== 1</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">&lt;</td>
<td align="center">Less than</td>
<td align="center">1 &lt; 3</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">&gt;</td>
<td align="center">Greater than</td>
<td align="center">4 &gt; 5</td>
<td align="center">false</td>
</tr>
<tr>
<td align="center">&lt;=</td>
<td align="center">Less than or equal to</td>
<td align="center">1 &lt;= 1</td>
<td align="center">true</td>
</tr>
<tr>
<td align="center">&gt;=</td>
<td align="center">Greater than or equal to</td>
<td align="center">10 &gt;= 20</td>
<td align="center">false</td>
</tr>
</tbody></table>
<h2>🧠 Logical operators</h2>
<table>
<thead>
<tr>
<th align="center">Operator</th>
<th align="center">Description</th>
<th align="center">Example</th>
</tr>
</thead>
<tbody><tr>
<td align="center">AND &amp;&amp;</td>
<td align="center">True if all conditions are true</td>
<td align="center">(x == 3)&amp;&amp;(y &gt; 0)</td>
</tr>
<tr>
<td align="center">OR ||</td>
<td align="center">True if any one of all conditions is true</td>
<td align="center">(x == 3)||(y &gt; 0)</td>
</tr>
<tr>
<td align="center">NOT !</td>
<td align="center">Toggles the condition result</td>
<td align="center">!(x == 3)</td>
</tr>
</tbody></table>
<blockquote>
<p><em>Note</em></p>
<p>Logical operators can return actual values, not just <code>true</code> or <code>false</code>.</p>
<pre><code class="language-js">"Hello" &amp;&amp; 5  // 5
"" || "Hi"    // "Hi"
!0            // true
</code></pre>
</blockquote>
<h2>❓Conditional operator</h2>
<p>Syntax:<br /><em>variable</em> <strong>=</strong> <em>condition</em> <strong>?</strong> <em>value_if_true</em> <strong>:</strong> <em>value_if_false</em></p>
<h4>Example</h4>
<pre><code class="language-js">isAdult = (age &gt;= 18) ? "Yes" : "No" ;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Datatypes]]></title><description><![CDATA[Datatypes are the type of data a variable can store JS is a dynamic language i.e., the type of the variable can change during runtime. The main difference…]]></description><link>https://rayonbyte.hashnode.dev/datatypes</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/datatypes</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 16:33:31 GMT</pubDate><content:encoded><![CDATA[<p>Datatypes are the type of data a variable can store</p>
<ul>
<li>Primitive types</li>
<li>Reference types</li>
</ul>
<h2>🧱 Primitive Types</h2>
<table>
<thead>
<tr>
<th>Type</th>
<th>description</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td>Number</td>
<td>Both integers and floating-point numbers (Number literal)</td>
<td><code>5</code>, <code>5.55</code>, <code>Infinity</code>, <code>NaN</code></td>
</tr>
<tr>
<td>String</td>
<td>Textual data wrapped in quotes (String literal)</td>
<td>"Hi", 'Hi', `Hi`</td>
</tr>
<tr>
<td>Boolean</td>
<td>Logical values: true or false</td>
<td><code>true</code>, <code>false</code></td>
</tr>
<tr>
<td>Undefined</td>
<td>A variable that has been declared but not assigned</td>
<td><code>undefined</code></td>
</tr>
<tr>
<td>Null</td>
<td>An intentional absence</td>
<td><code>null</code></td>
</tr>
</tbody></table>
<h4>Example</h4>
<pre><code class="language-js">let age = 15;
let name = "Rohan";
let isAdult = false;
let Lisence = undefined; // When it is not needed when empty
let favMovie = null; // When it is needed even when empty
</code></pre>
<h3>🎭 Dynamic typing</h3>
<p>JS is a dynamic language i.e., the type of the variable can change during runtime.</p>
<pre><code class="language-js">let data = 42;      // data is a Number
data = "Forty-two"; // data is now a String
data = true;        // data is now a Boolean
</code></pre>
<h2>🧩 Reference Types</h2>
<table>
<thead>
<tr>
<th>Type</th>
<th>description</th>
<th>Example</th>
</tr>
</thead>
<tbody><tr>
<td>Object</td>
<td>A collection of properties</td>
<td><code>{ name: "John", age: 30 }</code></td>
</tr>
<tr>
<td>Array</td>
<td>A list of values</td>
<td><code>[1,2,3]</code></td>
</tr>
<tr>
<td>Function</td>
<td>A block of code</td>
<td><code>() =&gt; {console.log("Hello Javascript")}</code></td>
</tr>
</tbody></table>
<h3>⚖️ Primitive vs Reference Types</h3>
<p>The main difference is how values are copied during assignment.</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Primitive Types</th>
<th>Reference Types</th>
</tr>
</thead>
<tbody><tr>
<td>Assignment</td>
<td>Copies the value</td>
<td>Copies the reference</td>
</tr>
<tr>
<td>Changes</td>
<td>Independent values</td>
<td>Variables can refer to the same object</td>
</tr>
<tr>
<td>Examples</td>
<td><code>Number</code>, <code>String</code>, <code>Boolean</code></td>
<td><code>Object</code>, <code>Array</code>, <code>Function</code></td>
</tr>
</tbody></table>
<h4>Primitive — Copy by Value</h4>
<pre><code class="language-js">let a = 10;
let b = a;
b = 20;

console.log(a); // 10
console.log(b); // 20
</code></pre>
<h4>Reference — Shared Object</h4>
<pre><code class="language-js">let a = { score: 10 };
let b = a;
b.score = 20;

console.log(a.score); // 20
console.log(b.score); // 20
</code></pre>
<p>Both variables refer to the same object, so modifying its properties through one variable affects the other.</p>
<blockquote>
<p><em>Note</em></p>
<p>JavaScript technically copies all assigned values. For objects, the copied value is a reference to the same object.</p>
</blockquote>
<h2>🔀 Type conversion</h2>
<p>Explicitly convert varaible from one datatype to another.<br />Eg: String -&gt; Number, Boolean -&gt; String</p>
<h3>typeof keyword</h3>
<p>typeof keyword is used to check the data type of a variable</p>
<pre><code class="language-js">let data = 10;
console.log(typeof data); //Number
</code></pre>
<p>JS has a bunch of built-in ways to convert types. Think of them in 3 buckets: string, number, boolean</p>
<h3>Convert to string</h3>
<pre><code class="language-js">String(123) // "123"
(true).toString // "true"
</code></pre>
<h3>Convert to Number</h3>
<pre><code class="language-js">Number("123") // 123
praseInt("456abc") // 456
**NOTE**
Number("123go") // NaN
</code></pre>
<h3>Convert to Boolean</h3>
<pre><code class="language-js">Boolean(0) // false
Boolean("Hello") // true
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Variables]]></title><description><![CDATA[Variables are the containers for storing values or expressions They are used to store data temporarily in the computer There are three methods of declaring…]]></description><link>https://rayonbyte.hashnode.dev/variables</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/variables</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 16:22:58 GMT</pubDate><content:encoded><![CDATA[<p>Variables are the containers for storing values or expressions
They are used to store data temporarily in the computer</p>
<h4>Example</h4>
<pre><code class="language-js">section = "3U"
console.log(section)
</code></pre>
<h2>⚖️ Rules for js variables</h2>
<ul>
<li>Case sensitive</li>
<li>Must start with an an alphabet or underscore</li>
<li>Cannot start with a number</li>
<li>Cannot use reserved words as variables</li>
<li>Should be meaningful</li>
<li>Cannot contain space or hyphen (-)</li>
</ul>
<h4>Here are few examples:</h4>
<ul>
<li>score ✅</li>
<li>_id ✅</li>
<li>01 🚫</li>
<li>await 🚫</li>
</ul>
<br />

<h2>📢 Declaration of varaibles</h2>
<p>There are three methods of declaring a variable in js</p>
<ul>
<li>let keyword</li>
<li>const keyword</li>
<li>var keyword</li>
</ul>
<table>
<thead>
<tr>
<th>Keyword</th>
<th>Access</th>
<th>Assignment</th>
<th>Initialise</th>
</tr>
</thead>
<tbody><tr>
<td>let</td>
<td>{...}</td>
<td>Reassignable</td>
<td>Optional</td>
</tr>
<tr>
<td>const</td>
<td>{...}</td>
<td>Final</td>
<td>Required</td>
</tr>
<tr>
<td>var</td>
<td>function</td>
<td>Reassignable</td>
<td>Optional</td>
</tr>
</tbody></table>
<h4>Reassignment</h4>
<pre><code class="language-js">let count = 0
count = 1 //This works

const count = 0
count = 1 //This doesn't work

var count = 0
count = 1 //This works
</code></pre>
<h4>Accessibility</h4>
<pre><code class="language-js">{
  let blockVariable = "I am hidden";
  var functionVariable = "I am visible";
}

console.log(blockVariable);    //This doesn't work
console.log(functionVariable); //This works
</code></pre>
<h3>Declearing multiple variables</h3>
<pre><code class="language-js">// Both works
let name="Rohan" , role="Student";

let name="Rohan";
let role="Student";   
</code></pre>
<blockquote>
<p><em>Note</em>  </p>
<ul>
<li>If you assign values to variables that have not yet been declared, the variables will automatically be declared.</li>
</ul>
<pre><code class="language-js">  x = 120; //  No error here
</code></pre>
<ul>
<li>"var" has some confusing behaviors regarding scope and hoisting, so modern developers generally avoid it in favor of let and const.</li>
</ul>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[JavaScript — Your First Step into Web Development]]></title><description><![CDATA[The web is more than just text and images — it's interactive!From responsive buttons to dynamic applications, JavaScript brings websites to life. Alongside…]]></description><link>https://rayonbyte.hashnode.dev/javascript-your-first-step-into-web-development</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/javascript-your-first-step-into-web-development</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Tue, 27 Oct 2026 16:11:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ade01b035a25e3ed5acb0a0/42d12e5f-eb33-4826-82f6-114782ffe3ff.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The web is more than just text and images — it's interactive!<br />From responsive buttons to dynamic applications, <strong>JavaScript</strong> brings websites to life.</p>
<p>Alongside HTML and CSS, JavaScript is one of the core technologies of web development, with tools like Node.js taking it beyond the browser.</p>
<p>In this <strong>Decode Javascript</strong> series, we'll explore JavaScript step by step, break down core concepts, and turn ideas into code. 💛</p>
<p><strong>Follow the series and join me on this journey from JavaScript fundamentals to building real-world applications. Let's learn, code, and grow together!</strong> ✨</p>
<h1>About this document</h1>
<p><strong>Name</strong>: Javascript notes<br /><strong>Created by</strong>: <a href="https://github.com/Rohan-Shridhar">Rohan S M</a><br /><strong>Created on</strong>: Jan 17, 2026<br /><strong>Info</strong>: This is a beginner friendly notes for javascript learners. If you want to learn advanced javasrcipt use this documentation as a first step towards your journey.</p>
<blockquote>
<p><em>Important</em></p>
<p><strong>This isn’t a complete JavaScript guide, just beginner-level notes 🐣</strong></p>
</blockquote>
<h3>What you will learn</h3>
<p>Basics of javascript like variables, operators, functions etc that are needed as a basic knowledge for learning angular, react, express, node and other javascript libraries and frameworks</p>
<blockquote>
<p><em>Tip</em></p>
<p><strong>Even if you don't want to code and just learn, it is fine :)</strong></p>
</blockquote>
<p><strong>No server setup is required—you can run simple JavaScript commands by following these steps.</strong></p>
<blockquote>
<p><em>Steps:</em></p>
<ul>
<li>Create a html file, say <code>index.html</code></li>
<li>Create a js file beside it, say <code>script.js</code></li>
<li>Connect the js file to the html file via script tag</li>
</ul>
<pre><code class="language-html">     &lt;script src="script.js"&gt;&lt;/script&gt;
</code></pre>
</blockquote>
<p><strong>With the files set up, open the HTML file in your browser and move on to editing the JS file.</strong></p>
<blockquote>
<ul>
<li>Install <a href="https://share.google/y2A0gAEhuLgAUDWSI">VS code</a> text editor on your system.</li>
<li>Install the extension called <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Live server</a> in VS code.</li>
<li>Right click on <code>index.html</code></li>
<li>Select Open with live server</li>
<li>Right click on the webpage in your browser</li>
<li>Select Inspect</li>
<li>Developer tools is opened</li>
<li>Go to Console to find the output of your javascript commands</li>
<li>Whenever you edit the js file and save it, immediately output is shown in the console.</li>
</ul>
</blockquote>
<h1>Table of Contents</h1>
<table>
<thead>
<tr>
<th align="right">#</th>
<th>Lesson</th>
<th>Explanation</th>
</tr>
</thead>
<tbody><tr>
<td align="right">1</td>
<td>Introduction to JavaScript</td>
<td>Understand what JavaScript is, why it is used, and how it works in web development.</td>
</tr>
<tr>
<td align="right">2</td>
<td>Variables</td>
<td>Learn how to declare variables using <code>var</code>, <code>let</code>, and <code>const</code> to store data.</td>
</tr>
<tr>
<td align="right">3</td>
<td>Datatypes</td>
<td>Explore primitive and reference types and understand the kinds of values JavaScript can handle.</td>
</tr>
<tr>
<td align="right">4</td>
<td>Operators</td>
<td>Learn how to perform arithmetic, comparison, logical, assignment, and other operations.</td>
</tr>
<tr>
<td align="right">5</td>
<td>Type Conversion and Coercion</td>
<td>Understand how JavaScript converts values between different datatypes explicitly and implicitly.</td>
</tr>
<tr>
<td align="right">6</td>
<td>Strings</td>
<td>Learn how to create, access, manipulate, and format text using strings.</td>
</tr>
<tr>
<td align="right">7</td>
<td>Math Object</td>
<td>Explore built-in mathematical properties and methods for performing calculations.</td>
</tr>
<tr>
<td align="right">8</td>
<td>Control Statements</td>
<td>Learn how to control program execution using <code>if</code>, <code>else</code>, and <code>switch</code> statements.</td>
</tr>
<tr>
<td align="right">9</td>
<td>Loops</td>
<td>Understand how to repeat code using <code>for</code>, <code>while</code>, <code>do...while</code>, and other loop constructs.</td>
</tr>
<tr>
<td align="right">10</td>
<td>Functions</td>
<td>Learn how to create reusable blocks of code using parameters, return values, and different function syntaxes.</td>
</tr>
<tr>
<td align="right">11</td>
<td>Objects</td>
<td>Understand how to store and organize related data using key-value pairs and methods.</td>
</tr>
<tr>
<td align="right">12</td>
<td>Arrays</td>
<td>Learn how to store and access ordered collections of values in a single variable.</td>
</tr>
<tr>
<td align="right">13</td>
<td>Array Methods</td>
<td>Explore methods such as <code>map()</code>, <code>filter()</code>, <code>reduce()</code>, and <code>find()</code> to manipulate arrays.</td>
</tr>
<tr>
<td align="right">14</td>
<td>Sets</td>
<td>Learn how to store unique values and perform common set operations.</td>
</tr>
<tr>
<td align="right">15</td>
<td>Maps</td>
<td>Understand how to store key-value pairs using keys of any datatype.</td>
</tr>
<tr>
<td align="right">16</td>
<td>Dates</td>
<td>Learn how to create, retrieve, and manipulate dates and times using the <code>Date</code> object.</td>
</tr>
<tr>
<td align="right">17</td>
<td>DOM</td>
<td>Understand how to access, modify, and create HTML elements using the Document Object Model.</td>
</tr>
<tr>
<td align="right">18</td>
<td>Events</td>
<td>Learn how to respond to user interactions such as clicks, keyboard input, and form submissions.</td>
</tr>
<tr>
<td align="right">19</td>
<td>JSON</td>
<td>Understand how to represent, parse, and serialize structured data using JavaScript Object Notation.</td>
</tr>
<tr>
<td align="right">20</td>
<td>Asynchronous JavaScript</td>
<td>Learn how JavaScript handles operations that complete later without blocking the main thread.</td>
</tr>
<tr>
<td align="right">21</td>
<td>Promises</td>
<td>Understand how promises represent the eventual success or failure of asynchronous operations.</td>
</tr>
<tr>
<td align="right">22</td>
<td>Async/Await</td>
<td>Learn how to write promise-based asynchronous code using a more readable, sequential syntax.</td>
</tr>
</tbody></table>
<blockquote>
<p><em>Note</em></p>
<p><strong>I am still learning; sorry if u dont see some topics 🥀</strong></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Building GitHub Authentication: From GitHub App Setup to OAuth Callback]]></title><description><![CDATA[Ever wondered what actually happens when you click "Continue with GitHub" on a website? For JSCrafts, I needed a way to identify users through their GitHub…]]></description><link>https://rayonbyte.hashnode.dev/building-github-authentication-from-github-app-setup-to-oauth-callback</link><guid isPermaLink="true">https://rayonbyte.hashnode.dev/building-github-authentication-from-github-app-setup-to-oauth-callback</guid><dc:creator><![CDATA[Rohan S Mirjankar]]></dc:creator><pubDate>Sun, 25 Oct 2026 13:26:27 GMT</pubDate><content:encoded><![CDATA[<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/7vo6jp59n8aq5ym3n12s.png" alt="Intro" style="display:block;margin:0 auto" />

<p>Ever wondered what actually happens when you click <strong>"Continue with GitHub"</strong> on a website?</p>
<p>For JSCrafts, I needed a way to identify users through their GitHub accounts and connect that identity to my application's user database.</p>
<p>I decided to use a GitHub App and implement the authorization flow in Next.js. In this article, I'll walk through the setup, environment variables, authorization redirect, callback handling, and how I connect the authenticated GitHub profile to my database.</p>
<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/n1tmyuydj4706tckctd0.png" alt="preview" style="display:block;margin:0 auto" />

<p>Let's break it down step by step.</p>
<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/kfw5gfcqeeesdgecij1l.png" alt="Section 1" style="display:block;margin:0 auto" />

<p>A GitHub App is like a formal partnership agreement between your application and GitHub users.</p>
<p>Imagine building a passport automation system where you need to authenticate new users. Forget the technical jargon for a moment. Think of it this way: just as a Social Security Number (SSN) can help uniquely identify an individual, GitHub authentication allows your app to identify and verify users through their GitHub accounts.</p>
<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/kn16onxsr589ifr7q6lk.png" alt="Section 2" style="display:block;margin:0 auto" />

<p>GitHub offers several ways to authenticate users and access its resources, including Personal Access Tokens, OAuth Apps, and GitHub Apps. Each serves a different purpose, but I needed an approach that would support user authentication while allowing my application to request specific permissions for GitHub resources.</p>
<p>I chose a <strong>GitHub App</strong> because it offers granular permissions and supports acting both as an application and on behalf of authorized users. This made it a suitable fit for my application's authentication and integration requirements.</p>
<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/wav7q9j7yi8mbhiv3diw.png" alt="Section 3" style="display:block;margin:0 auto" />

<p>I started by navigating to:</p>
<p>GitHub → Settings → Developer settings → GitHub Apps → New GitHub App</p>
<blockquote>
<p><em>GitHub Apps are registered through the Developer settings section of a GitHub account or organization.</em></p>
</blockquote>
<p>Configured the basic details:</p>
<ol>
<li><p>Tha callback URL:<br />The callback URL is the address GitHub sends the user back to after they approve (or deny) login on GitHub's site.</p>
<blockquote>
<p><em>Where do you want the user to be sent after github app does its job?</em></p>
</blockquote>
<p>I registered every URL I will be using Development: <a href="http://localhost:3000/api/auth/github/callback">http://localhost:3000/api/auth/github/callback</a> Production: <a href="https://jscrafts.vercel.app/api/auth/github/callback">https://jscrafts.vercel.app/api/auth/github/callback</a></p>
</li>
<li><p>Permissions<br />Permissions determine what a GitHub App can access or modify. Granting excessive permissions increases the potential impact of a compromised application.</p>
<p>For the initial setup, I kept repository access read-only and limited the permissions to the requirements of the integration.</p>
</li>
<li><p>Webhooks<br />GitHub webhooks allow an application to receive event notifications, such as repository-related changes, without continuously polling the API.</p>
<p>I planned to use a webhook endpoint for future repository integration, but the endpoint had not yet been implemented.</p>
<p>Therefore, I deferred webhook configuration until the application had a working endpoint. When webhooks are enabled, the webhook URL and secret must be configured appropriately.</p>
</li>
<li><p>Creating the .env.local File I added the following environment variable names:</p>
</li>
</ol>
<pre><code class="language-env">    GITHUB_CLIENT_ID=
    GITHUB_CLIENT_SECRET=
    GITHUB_APP_ID= 
    GITHUB_PRIVATE_KEY=
    GITHUB_WEBHOOK_SECRET=
</code></pre>
<table>
<thead>
<tr>
<th>Value</th>
<th>Meaning</th>
<th>Usecase</th>
</tr>
</thead>
<tbody><tr>
<td>GITHUB_CLIENT_ID</td>
<td>A public identifier for the github app. Like a username.</td>
<td>It appears in the URL when redirecting users to GitHub</td>
</tr>
<tr>
<td>GITHUB_CLIENT_SECRET</td>
<td>A secret password for the app. Like a password paired with the client ID.</td>
<td>Exchanging the authorization code for an access token</td>
</tr>
<tr>
<td>GITHUB_APP_ID</td>
<td>A numeric ID for the GitHub App itself</td>
<td>When your application wants to read repositories on its own behalf.</td>
</tr>
<tr>
<td>GITHUB_PRIVATE_KEY</td>
<td>A cryptographic key (.pem file) that proves "I really am the GitHub App."</td>
<td>Generating JWTs to authenticate as the GitHub App itself, used later</td>
</tr>
<tr>
<td>GITHUB_WEBHOOK_SECRET</td>
<td>A shared password used to verify that incoming webhook requests actually came from GitHub.</td>
<td>The eventual /api/github/webhook route</td>
</tr>
</tbody></table>
<img src="https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/uwgiq1i9oey6n9onbhma.png" alt="Section 4" style="display:block;margin:0 auto" />

<p>Before implementing, understand the actors in our implementation.<br />The browser is the user, your app server, GitHub's website and GitHub's API.<br />We need two separate routes to complete the entire flow.</p>
<h3>Route 1: Send the user to GitHub.</h3>
<p>The URL looks like this:</p>
<pre><code class="language-https">    https://github.com/login/oauth/authorize
    ?client_id=[GITHUB-CLIENT_ID]
    &amp;redirect_uri=[CALLBACK_URL]
</code></pre>
<p>The file you need create is <code>src/app/api/auth/github/route.ts</code>:</p>
<pre><code class="language-js">export async function GET() {
  // 1. Read the client ID from env
  const clientId = process.env.GITHUB_CLIENT_ID;
  if (!clientId) {
    return NextResponse.json(
      { error: 'GitHub client ID is not configured' },
      { status: 500 },
    );
  }

  // 2. Figure out which callback URL to use
  const redirectUri =
    process.env.NODE_ENV === 'production'
      ? 'https://jscrafts.vercel.app/api/auth/github/callback'
      : 'http://localhost:3000/api/auth/github/callback';

  // 3. Build the GitHub URL
  const githubUrl = new URL('https://github.com/login/oauth/authorize');
  githubUrl.searchParams.set('client_id', clientId);
  githubUrl.searchParams.set('redirect_uri', redirectUri);

  // 4. Send the browser there
  return NextResponse.redirect(githubUrl);
}
</code></pre>
<p>When the browser lands on that URL, github checks the client_id and responds to the real Github App.<br />If they approve --&gt; redirect to the callback url along with <code>?code=ABC123</code><br />If they deny --&gt; redirects back with <code>?error=access_denied</code><br />The code that it sends back when approved is important, its short-lived, single-use and is used with CLIENT_ID for fetching github user details for initial profile building.</p>
<h3>Route 2: Receive the user back from GitHub</h3>
<p>The file you need to <code>src/app/api/auth/github/callback/route.ts</code><br />This is the meat of the login. It does four things in order:</p>
<h4>Part 1: Read the code or error</h4>
<pre><code class="language-js">export async function GET(request: NextRequest) {
  const searchParams = request.nextUrl.searchParams;
  const code = searchParams.get('code');
  const error = searchParams.get('error');

  if (error) {
    return NextResponse.redirect(new URL('/?error=github_denied', request.url));
  }

  if (!code) {
    return NextResponse.redirect(new URL('/?error=missing_code', request.url));
  }
  // ... continue
}
</code></pre>
<h4>Part 2: Exchange code for access token</h4>
<pre><code class="language-js">const tokenResponse = await fetch('https://github.com/login/oauth/access_token', {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    client_id: clientId,
    client_secret: clientSecret,
    code,
    redirect_uri: redirectUri,
  }),
});

const tokenData = await tokenResponse.json();

if (!tokenResponse.ok || !tokenData.access_token) {
  return NextResponse.redirect(new URL('/?error=github_token_exchange', request.url));
}
</code></pre>
<h4>Part 3: Fetch the user's profile</h4>
<pre><code class="language-js">const githubUserResponse = await fetch('https://api.github.com/user', {
  headers: {
    Authorization: `Bearer ${tokenData.access_token}`,
    Accept: 'application/vnd.github+json',
  },
});

const githubUser = await githubUserResponse.json();
</code></pre>
<p>GitHub returns something like this:</p>
<pre><code class="language-json">{
  "id": 12345678,
  "login": "rohan",
  "name": "Rohan",
  "avatar_url": "https://avatars.githubusercontent.com/u/...",
  "html_url": "https://github.com/rohan"
}
</code></pre>
<h4>Part 4: Create the JSCrafts user</h4>
<pre><code class="language-js">await connectDB();

const user = await User.findOneAndUpdate(
  { githubId: String(githubUser.id) },
  {
    githubId: String(githubUser.id),
    username: githubUser.login,
    displayName: githubUser.name ?? githubUser.login,
    avatarUrl: githubUser.avatar_url,
    profileUrl: githubUser.html_url,
    email: primaryEmail,
  },
  {
    new: true,   // return the updated document
    upsert: true, // create it if it doesn't exist
  },
);
</code></pre>
<p>What <code>findOneAndUpdate</code> with <code>upsert: true</code> does:</p>
<pre><code class="language-txt">1. Look for a User with githubId = "12345678"
2. If found → update its fields, return it
3. If not found → create a new User with all these fields, return it
This is the classic "find-or-create" pattern. It handles both first-time and returning users in a single query.
</code></pre>
<p><em>Why use githubId as the key?</em></p>
<ul>
<li>It's stable — usernames can change, IDs can't.</li>
<li>It's unique — each GitHub account has exactly one ID.</li>
</ul>
<p>Why <code>new: true</code> ?<br />Without it, MongoDB returns the old document (before the update). With it, you get the new one, which is what you want for the session step.</p>
<hr />
<h2>What I Learned</h2>
<p>Building GitHub authentication for JSCrafts helped me understand three important things:</p>
<ul>
<li><strong>Permission scoping matters:</strong> Request only the access your application actually needs.</li>
<li><strong>OAuth security matters:</strong> State validation, secure credential handling, and proper error handling are essential parts of the flow.</li>
<li><strong>Authentication has multiple layers:</strong> Authenticating a user through GitHub is different from authenticating the GitHub App itself.</li>
</ul>
<p>This is an important step in building JSCrafts. The next step is to ensure that the authorization flow is backed by secure session management and that every protected route checks the user's session.</p>
]]></content:encoded></item></channel></rss>