<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged javascript-beginners</title>
<link>https://coderlegion.com/tag/javascript-beginners</link>
<description>Powered by Question2Answer</description>
<item>
<title>How I talk with the DOM?</title>
<link>https://coderlegion.com/5279/how-i-talk-with-the-dom</link>
<description>&lt;h3 id=&quot;intro-&quot;&gt;Intro.&lt;/h3&gt;
&lt;p&gt;In the past I made use of the &quot;document.querySelector(All) &quot; all over the place and what often resulted in &quot;undefined&quot; errors.&lt;/p&gt;
&lt;p&gt;To be honest, it took me a long time to find a solution for this. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;At first I began with creating a function for the &quot;document.querySelector(All) (that I to date still use!)&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
export async function elQuery(...args){
  const [elem,el_all=false,el_parent] = args;
  let el;
  if(true === el_all){
    if(el_parent) el = el_parent.querySelectorAll(elem);
    else el = document.querySelectorAll(elem);
  }else{
    if(el_parent) el = el_parent.querySelector(elem);
    else el = document.querySelector(elem);
  }
  return await el;
}
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Swapping function calls up and down within my index.js. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using &quot;setTimeout()&quot; and so on!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There were some improvements with this steps but it was still struggling to get my queries right.&lt;/p&gt;
&lt;h3 id=&quot;a-quantum-leap-forward-&quot;&gt;A Quantum Leap forward.&lt;/h3&gt;
&lt;p&gt;Finally I found a way to get this done by using &lt;strong&gt;Map()&lt;/strong&gt; and that is what I want to share with you. &lt;/p&gt;
&lt;h3 id=&quot;first-this-&quot;&gt;First this.&lt;/h3&gt;
&lt;p&gt;I use javascript with a module approach, working with a folder/file structure and a bunch of custom (reusable) functions, aside of that I use classes too.&lt;/p&gt;
&lt;p&gt;The given example here is a reflection of that!&lt;/p&gt;
&lt;h5 id=&quot;1-structure-&quot;&gt;1 structure:&lt;/h5&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
assets/
  scripts/
    factory/
     dom_objects.js
     functions.js
     generals.js
     handlers.js
    modules/
     actions/
      set_actions_1.js
      set_actions_2.js
      set_default_action.js
      get_actions.js
     callbacks/
      sub_callbacks_1.js
      sub_callbacks_2.js
     defaults/
      set_defaults.js
     mdl_factory/
      //module specific files
     templates/
      sub_templates_1.js
      sub_templates_2.js

    index.js
&lt;/pre&gt;
&lt;h5 id=&quot;2-dom-objects-js-&quot;&gt;2 dom_objects.js:&lt;/h5&gt;
&lt;p&gt;That's the file where I collect my dom objects and it holds two functions, called getBaseObjects and getExtendedObjects. &lt;/p&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
// assets/scripts/factory/dom_objects.js */
import * as FT from './functions.js';
export const getBaseObjects = async()=&amp;gt;{
  const map = new Map([['base_objects',{
    vvp: window.visualViewport,
    location_base: window.location.origin,
    body: document.body,
    wrap_ctn: await FT.elQuery('div.wrap.container', false, self.body),
    main_elem: await FT.elQuery('main', false, self.wrap_ctn), 
    actions_block: await FT.elQuery('.actions-block_ctn',false,self.wrap_ctn),
     //other base objects
  }]]);
  return map.get('base_objects');
}
 
export const getExtendedObjects = async (base_dom)=&amp;gt;{
  const {vvp,location_base,body,main_elem,actions_block} = base_dom;
  const map = new Map([['ext_objects',{
    vvp,location_base,body,main_elem,actions_block,
    main_sub_ctn: await FT.elQuery('div.main_sub_ctn',false,self.main_elem),
    //option 1 (not recommended), is just to show that you can group objects
    action_items:{
      action_item_1: await FT.elQuery('.action-item-1',false,self.actions_block),
      action_item_2: await FT.elQuery('.action-item-2',false,self.actions_block),
      action_item_3: await FT.elQuery('.action-item-3',false,self.actions_block),
      action_item_4: await FT.elQuery('.action-item-4',false,self.actions_block),
    },
    //option 2 (if your actions_block isn't going to change)
    action_items: await FT.elQuery('.action-item',true,self.actions_block),
    //option 3 (if your actions_block has live events and is going to change)
    action_items: await FT.getClassHelper('action-item',self.actions_block), 
    // uses 'getElementsByClassName'
    //-----------------------------
    //other ext objects
  }]]);
  return map.get('ext_objects');
}
&lt;/pre&gt;
&lt;h5 id=&quot;explanation-&quot;&gt;explanation:&lt;/h5&gt;
&lt;p&gt; I have created two functions here but for a reason.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;getBaseObjects&lt;/strong&gt; have values that are available as soon as the website loads and will never give an &lt;em&gt;undefined error&lt;/em&gt;:&lt;/p&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
//assets/scripts/index.js
 import {getBaseObjects} from './factory/dom_objects.js';
 import {getActions} from './modules/actions/get_actions.js';
 (async ()=&amp;gt;{
   const base_elems = await getBaseObjects();
   await getActions(base_elems);
   //sure, there are more functions and classes that I call here.
 })();
&lt;/pre&gt;
&lt;h5 id=&quot;the-steps-here-&quot;&gt;The steps here:&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;'getBaseObjects' is imported from 'dom_objects.js'.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;this function is called and applied to a const 'base_elems'.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;'getActions' is called from 'get_actions.js'.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;the values of step2 are passed as an arg to the 'getActions(base_elems)' function.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt; From here, the objects{keys:values} of 'base_elems' are available in the getActions function.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;getExtendedObjects&lt;/strong&gt; might have values that has not been created yet and could give an &lt;em&gt;undefined&lt;/em&gt; error if so? &lt;/p&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
/** modules/actions/get_actions.js */
import {getExtendedObjects} from './../../factory/dom_objects.js';
import * as SA1 from './set_actions_1.js';
export const getActions = async(base_elems)=&amp;gt;{
 const ext_elems = await getExtendedObjects(base_elems);
 await setActions1(ext_elems);
}
&lt;/pre&gt;
&lt;h5 id=&quot;the-steps-here--1&quot;&gt;The steps here:&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;'getExtendedObjects' is imported from 'dom_objects.js'.&lt;/li&gt;
&lt;li&gt;SA1.setActions1 is imported from 'set_actions_1.js'.&lt;/li&gt;
&lt;li&gt;function 'getActions' has been created together with a param 'base_elems'.&lt;/li&gt;
&lt;li&gt;within that function, 'getExtendedObjects' is called and args 'base_elems' are applied to it. Then this function is applied to a const 'ext_elems'.&lt;/li&gt;
&lt;li&gt;'SA1.setActions1' is called and has args 'ext_elems' applied to it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;From here &lt;strong&gt;all objects&lt;/strong&gt; are available when called. &lt;/p&gt;
&lt;h4 id=&quot;in-a-real-situation-&quot;&gt;In a real situation.&lt;/h4&gt;
&lt;p&gt;In a real situation you only want the objects you need for a certain part of your webpage. &lt;/p&gt;
&lt;p&gt;Let say:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;'header' related objects for in the header.&lt;/li&gt;
&lt;li&gt;'main' related objects for in the main.&lt;/li&gt;
&lt;li&gt;'footer' related objects for in the footer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The best way to do that is to create nested object groups in your Map(). &lt;/p&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
const map = new Map([['ext_objects',{
  header_objects:{
    //header objects here
  },
  main_objects:{
    //main objects here
  },
  footer_objects:{
    //footer objects here
  },
})    
&lt;/pre&gt;
&lt;p&gt;Then in your 'getActions', you are doing this: &lt;/p&gt;
&lt;pre style=&quot;background:#62686d; color:#fff&quot;&gt;
export const getActions = async(base_elems)=&amp;gt;{
  const ext_elems = await getExtendedObjects(base_elems);
  //note: this is called 'destructuring', for objects it is {} and for arrays []
  const {header_objects,main_objects,footer_objects} = ext_elems;
  await headerAction(header_objects);
  await mainAction(main_objects);
  await footerAction(foot_objects);
}
&lt;/pre&gt;
&lt;p&gt;Now, each action get it's own objects.&lt;/p&gt;
&lt;p&gt;Enough for now!&lt;br&gt;
There is way more to say about it but I think this is enough for now! &lt;/p&gt;
&lt;h4 id=&quot;cheers-&quot;&gt;Cheers!&lt;/h4&gt;
</description>
<category>Objects</category>
<guid isPermaLink="true">https://coderlegion.com/5279/how-i-talk-with-the-dom</guid>
<pubDate>Wed, 10 Sep 2025 16:53:31 +0000</pubDate>
</item>
<item>
<title>How I load javascript?</title>
<link>https://coderlegion.com/5224/how-i-load-javascript</link>
<description>&lt;h3 id=&quot;intro--1&quot;&gt;Intro.&lt;/h3&gt;
&lt;p&gt;It's based on an old article that I've read a while back about &lt;em&gt;bulletproof loading of webcomponents&lt;/em&gt; and written by &lt;a rel=&quot;nofollow&quot; href=&quot;http:////https://gomakethings.com/bulletproof-web-component-loading/&quot;&gt;Chris Go Make Things&lt;/a&gt;, someone who knows a lot more about webdesign as me.&lt;br&gt;
The article was about loading  loading js in the footer or in the head and using 'async/defer' .&lt;/p&gt;
&lt;h3 id=&quot;his-approach-&quot;&gt;His Approach.&lt;/h3&gt;
&lt;p&gt;His 'bulletproof' approach was by using document.readyState and DOMContentLoaded in his component classes. &lt;/p&gt;
&lt;h3 id=&quot;my-idea-&quot;&gt;My idea.&lt;/h3&gt;
&lt;p&gt;It might be bulletproof but complex and hard to maintain The way I do that is &lt;strong&gt;Simple&lt;/strong&gt;, &lt;strong&gt;Bulletproof&lt;/strong&gt;, &lt;strong&gt;Fast&lt;/strong&gt; and hardly needs any maintenance. &lt;/p&gt;
&lt;h3 id=&quot;how-i-load-js-then-&quot;&gt;How I load js then.&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First step is to have an index.js within the scripts folder and that contains the following:&lt;/p&gt;
&lt;pre&gt;//the imports on top. 
(async ()=&amp;gt;{
    /** 
      This is the place where all the js logic ends up but in the right order!
   */
})();
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Second step, within your index.html this: &lt;/p&gt;
&lt;p&gt;&lt;em style=&quot;background:yellow; padding: 2px&quot;&gt;&lt;br&gt;
&amp;lt;script type='module' src='./path/to/scripts/index.js'&amp;gt; &amp;lt;/script&amp;gt;&lt;br&gt;
&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;explanation&quot;&gt;Explanation&lt;/h3&gt;
&lt;p&gt;At the first step, the code has been placed in an async (Immediately Invoked Function Expression)! That iife, is the final place where all my js stuff ends up. &lt;/p&gt;
&lt;h4 id=&quot;this-way-&quot;&gt;This way.&lt;/h4&gt;
&lt;p&gt;There is no need for using 'DOMContentLoaded' because the promise is 100% fulfilled before it's passed to my index.html. So what I get is a single substance that is complete and ready to use. &lt;/p&gt;
&lt;p&gt;Actually, I rarely look at it because there is no need for! &lt;/p&gt;
&lt;h4 id=&quot;note-&quot;&gt;Note!&lt;/h4&gt;
&lt;p&gt;Placing all js stuff in the right order within you index.js is important! Otherwise, things might give errors because of lacking dependenties.&lt;/p&gt;
&lt;p&gt;More about &lt;strong&gt;IIFE&lt;/strong&gt; at &lt;a rel=&quot;nofollow&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/IIFE&quot;&gt;MDN(IIFE)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That's it!&lt;/p&gt;
</description>
<category>Frontend Dev</category>
<guid isPermaLink="true">https://coderlegion.com/5224/how-i-load-javascript</guid>
<pubDate>Sun, 07 Sep 2025 09:56:58 +0000</pubDate>
</item>
<item>
<title>What is Javascript and How It Powers Modern Websites</title>
<link>https://coderlegion.com/4623/what-is-javascript-and-how-it-powers-modern-websites</link>
<description>&lt;p&gt;Picture this: You click a button on a webpage, and absolutely nothing happens .&lt;/p&gt;
&lt;p&gt;There are no dropdown menus to explore, no fun animations to enjoy, and no validations on form submissions.&lt;/p&gt;
&lt;p&gt;Basically, a &lt;em&gt;lifeless piece of the internet&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;That's what the web would look like without Javascript. &lt;/p&gt;
&lt;h2 id=&quot;what-is-javascript-&quot;&gt;What is Javascript?&lt;/h2&gt;
&lt;p&gt;Javascript, often abbreviated as &quot;JS&quot;, is the wacky genius of modern web development.&lt;/p&gt;
&lt;p&gt;It's the magic wand  that transforms static, boring HTML and CSS websites into lively, interactive, and engaging experiences that are hard to stop scrolling through.&lt;/p&gt;
&lt;p&gt;Simply put, Javascript is a programming language that adds &lt;em&gt;interactivity, animations, and dynamic features&lt;/em&gt; to websites. Whether it's &lt;em&gt;a pop-up&lt;/em&gt; (), &lt;em&gt;a dropdown menu&lt;/em&gt; (), or &lt;em&gt;an animation that dances across your screen&lt;/em&gt;—&lt;strong&gt;Javascript is behind the curtain pulling the strings&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It's one of the &lt;strong&gt;holy trinity of web development&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;HTML – gives structure&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;CSS – makes it pretty&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Javascript – brings it to life&lt;/em&gt;&lt;/strong&gt; ⚡&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It's primarily a &lt;strong&gt;&lt;em&gt;client-side language&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;event-driven&lt;/em&gt;&lt;/strong&gt;, and runs directly in your browser without requiring installation. Magic? Nope—just good old scripting.&lt;/p&gt;
&lt;p&gt;Technically:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It's &lt;strong&gt;interpreted&lt;/strong&gt; (runs directly, no compiling)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's &lt;strong&gt;dynamically typed&lt;/strong&gt; (you don't have to declare types — more on this in a later article)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses &lt;strong&gt;prototypal inheritance&lt;/strong&gt; instead of classical OOP (we'll unpack this later — no stress if that sounds unfamiliar!)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It runs using something called a &lt;strong&gt;Javascript engine&lt;/strong&gt; inside your browser (don't worry, we'll explain what that means soon)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Oh, and it also works on the server side, but we'll dive into that later.&lt;/p&gt;
&lt;h2 id=&quot;-a-brief-history-of-javascript&quot;&gt;&lt;strong&gt; A Brief History of Javascript&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Back in &lt;strong&gt;&lt;em&gt;1995&lt;/em&gt;, Brendan Eich&lt;/strong&gt; developed Javascript in just &lt;strong&gt;10 days&lt;/strong&gt;. Yes, that's faster than most of us write a to-do list .&lt;/p&gt;
&lt;p&gt;Originally called &lt;strong&gt;Mocha&lt;/strong&gt; (mmm, coffee), then &lt;strong&gt;Live Script&lt;/strong&gt;, it was finally &lt;strong&gt;rebranded as Javascript&lt;/strong&gt; because, hey, Java was trendy at the time ☕.&lt;/p&gt;
&lt;p&gt;Despite the misleading name, &lt;strong&gt;Java ≠ Javascript&lt;/strong&gt;—that's like comparing ham to a hamster.&lt;/p&gt;
&lt;p&gt;Fast-forward to today. Javascript has grown from a toy language into one of the web's core technologies, alongside HTML and CSS. It is now &lt;strong&gt;&lt;em&gt;standardised under ECMAScript&lt;/em&gt;&lt;/strong&gt; and powers everything on the web except your morning coffee .&lt;/p&gt;
&lt;h2 id=&quot;-core-features-of-javascript&quot;&gt;&lt;strong&gt;✨ Core Features of Javascript&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Javascript isn't just pretty code—it's flexible, feisty, and full of surprises.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamically Typed&lt;/strong&gt; – like, whatever &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event-Driven&lt;/strong&gt; – reacts to user clicks, scrolls, and tantrums .&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fast&lt;/strong&gt; – thanks to powerful browser engines ⚡&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Versatile&lt;/strong&gt; – works on browsers, servers, phones, fridges (not kidding !)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It Has Superpowers (via Ecosystem) -&lt;/strong&gt; There's a massive library of tools and frameworks. React, Vue, D3, Express, Socket.io — you're never alone in Javascript land .&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It's like that colleague who can debug complex code with ease, seamlessly integrate APIs, and always finds time to collaborate on projects. &lt;/p&gt;
&lt;h2 id=&quot;how-to-run-javascript-in-a-browser&quot;&gt;&lt;strong&gt;How to Run Javascript in a Browser&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Javascript is &lt;strong&gt;built right into all major browsers&lt;/strong&gt; (&lt;em&gt;Chrome, Firefox, Safari, Edge&lt;/em&gt;), like a secret snack drawer .&lt;/p&gt;
&lt;p&gt;You can run Javascript in the browser in a few simple ways:&lt;/p&gt;
&lt;h4 id=&quot;1-the-developer-console-for-quick-testing-&quot;&gt;&lt;strong&gt;1. The Developer Console (For Quick Testing)&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open &lt;em&gt;Chrome&lt;/em&gt; (or any browser).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Press &lt;code&gt;F12&lt;/code&gt; or &lt;strong&gt;right-click → Inspect&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The browser's &lt;strong&gt;developer tools&lt;/strong&gt; will open up. Go to the &lt;strong&gt;Console Tab&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Type this, Hit Enter and watch the magic unfold ✨&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;console.log(&quot;Hello, World! &quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12213951383119350445&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;2-add-it-directly-to-html&quot;&gt;&lt;strong&gt;2. Add it directly to HTML&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Use the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag inside your HTML file - &lt;code&gt;index.html&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;Javascript Test&amp;lt;/h1&amp;gt;

        &amp;lt;script&amp;gt;
            alert(&quot;Hello, World! &quot;);
        &amp;lt;/script&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Open the &lt;code&gt;index.html&lt;/code&gt; file in your favorite browser.&lt;/p&gt;
&lt;p&gt;Boom! JS is live and will greet you like a chatty bot!.&lt;/p&gt;
&lt;h2 id=&quot;how-javascript-gets-executed&quot;&gt;&lt;strong&gt;How Javascript gets executed&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Before getting our hands dirty with Javascript code, it is better to have a basic understanding of how Javascript gets executed. ☄️&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Javascript alone is just syntax and logic&lt;/em&gt;; just like any other programming language, &lt;strong&gt;&lt;em&gt;a compiler or an interpreter is needed to execute Javascript&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Well, there are still ongoing debates about whether Javascript is a compiled language or an interpreted language. It would be &lt;strong&gt;&lt;em&gt;more accurate to say that Javascript in modern times is both compiled and interpreted, specifically through JIT (Just-In-Time) Compilation&lt;/em&gt;&lt;/strong&gt;. More on this later.&lt;/p&gt;
&lt;p&gt;To interact with web pages, forms, user events, or fetch data, it requires &lt;strong&gt;&lt;em&gt;a host&lt;/em&gt;&lt;/strong&gt; where &lt;strong&gt;&lt;em&gt;this JIT Compiler (a Javascript engine) is embedded&lt;/em&gt;&lt;/strong&gt;, much like the engine of a car—essential for driving the experience forward and making everything run smoothly. &lt;/p&gt;
&lt;h3 id=&quot;what-is-a-hosted-environment-&quot;&gt;&lt;strong&gt;What Is a Hosted Environment? ⚙️&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;A hosted environment — or, as seasoned developers call it, &lt;strong&gt;the runtime environment&lt;/strong&gt; — is the setup provided by the host system, &lt;strong&gt;&lt;em&gt;such as a web browser or Node.js&lt;/em&gt;&lt;/strong&gt;, that embeds and interacts with the &lt;strong&gt;&lt;em&gt;Javascript engine&lt;/em&gt;&lt;/strong&gt;. This environment offers some juicy extras — such as &lt;code&gt;fetch&lt;/code&gt;, &lt;code&gt;document&lt;/code&gt;, and &lt;code&gt;setTimeout&lt;/code&gt; — that the core Javascript language doesn't include.&lt;/p&gt;
&lt;h4 id=&quot;key-examples-of-hosted-environments-for-javascript&quot;&gt;&lt;strong&gt;Key Examples of Hosted Environments for Javascript&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web Browsers (Client-side Hosted Environment)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOM access&lt;/strong&gt;: via &lt;code&gt;document&lt;/code&gt;, &lt;code&gt;window&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Browser APIs&lt;/strong&gt;: like &lt;code&gt;fetch()&lt;/code&gt;, &lt;code&gt;alert()&lt;/code&gt;, &lt;code&gt;console.log()&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Timers&lt;/strong&gt;: &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;setInterval&lt;/code&gt;. etc&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Code runs in the &lt;strong&gt;&lt;em&gt;context of a webpage&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Controlled by the &lt;strong&gt;&lt;em&gt;browser's security and event loop&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can access and manipulate the &lt;strong&gt;&lt;em&gt;DOM&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node.js (Server-side Hosted Environment)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;File System:&lt;/strong&gt; via &lt;code&gt;fs&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network:&lt;/strong&gt; &lt;code&gt;http&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other APIs:&lt;/strong&gt; &lt;code&gt;process&lt;/code&gt;, &lt;code&gt;require&lt;/code&gt;, etc.&lt;/p&gt;
&lt;p&gt;  &lt;strong&gt;Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Code runs &lt;strong&gt;&lt;em&gt;on a server&lt;/em&gt;&lt;/strong&gt;, often with access to the filesystem and network.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No DOM or browser-specific features.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Includes an &lt;strong&gt;&lt;em&gt;event-driven, non-blocking I/O model&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other Examples&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deno:&lt;/strong&gt; Secure TypeScript/Javascript runtime with modern APIs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edge Functions / Serverless Platforms:&lt;/strong&gt; Cloud-hosted Javascript executed in response to HTTP requests.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All major browsers have &lt;strong&gt;&lt;em&gt;Javascript engines built into them&lt;/em&gt;&lt;/strong&gt; (Chrome, Firefox, Safari, Edge)&lt;/p&gt;
&lt;p&gt;Some well-known JS engines are,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Chrome&lt;/strong&gt; → V8 Engine &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Firefox&lt;/strong&gt; → SpiderMonkey &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Safari&lt;/strong&gt; → JavaScriptCore &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;what-happens-when-you-load-a-web-page-&quot;&gt;&lt;strong&gt;What happens when you load a web page?&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;So, how exactly does Javascript run when you load a web page? &lt;/p&gt;
&lt;p&gt;Here's a simplified overview that doesn't require a PhD:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You load a page&lt;/strong&gt; – Browser reads the HTML and finds a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Javascript engine&lt;/strong&gt; (like V8 in Chrome or SpiderMonkey in Firefox) kicks in.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The engine parses the code&lt;/strong&gt;, converts it into something called bytecode or machine code.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;It executes the code line by line&lt;/strong&gt;, handling events, functions, loops, and more.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It interacts with the browser's APIs, including the Document Object Model (DOM) and the Browser Object Model (BOM), to enable engaging functionality on the screen.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The way everything unfolds within the browser and our Javascript engine is a fascinating process, which we will explore in more detail in a future article.&lt;/p&gt;
&lt;h2 id=&quot;-how-to-add-javascript-to-a-website&quot;&gt;&lt;strong&gt; How to Add Javascript to a Website&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;There are three classic ways to add Javascript:&lt;/p&gt;
&lt;h4 id=&quot;-1-inline-javascript&quot;&gt;&lt;strong&gt; 1. Inline Javascript&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Directly inside HTML elements.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;button onclick=&quot;alert('You clicked!')&quot;&amp;gt;Click me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;✅ &lt;em&gt;Easy to test. ❌ Not scalable or maintainable&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;-2-internal-scripts-in-tags&quot;&gt;&lt;strong&gt; 2. Internal Scripts in  Tags&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; in the HTML.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&amp;lt;script&amp;gt;
    console.log(&quot;This runs when the page loads.&quot;);
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Great for small scripts during development.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;-3-external-javascript-files&quot;&gt;&lt;strong&gt; 3. External Javascript Files&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In a separate HTML file - &lt;code&gt;index.html&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;!-- In index.html - Withing &amp;lt;body&amp;gt; tag --&amp;gt;
&amp;lt;script src=&quot;script.js&quot; defer&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Inside&lt;/strong&gt; &lt;code&gt;script.js&lt;/code&gt;&lt;strong&gt;:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// script.js
console.log(&quot;This is coming from an external file.&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Use defer to make sure the script runs &lt;em&gt;after&lt;/em&gt; the HTML has loaded.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Best practice&lt;/strong&gt;: Keeping your Javascript in a separate &lt;code&gt;.js&lt;/code&gt; file helps to create cleaner and easier-to-manage code. No one likes spaghetti code. &lt;/p&gt;
&lt;h2 id=&quot;-how-javascript-powers-modern-websites&quot;&gt;&lt;strong&gt;⚡ How Javascript Powers Modern Websites&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Javascript is &lt;em&gt;the heartthrob of modern web design&lt;/em&gt; ❤️. Well, yeah, no second thoughts on that.&lt;/p&gt;
&lt;p&gt;It's everywhere, like the air we breathe , and it's lightning-fast ⚡.&lt;/p&gt;
&lt;p&gt;It transforms static pages into &lt;strong&gt;&lt;em&gt;dynamic, interactive experiences&lt;/em&gt;&lt;/strong&gt;. From simple interactions like button clicks to full-scale SPAs (Single-Page Applications) that feel like native apps, Javascript is the engine driving modern UX.&lt;/p&gt;
&lt;p&gt;With powerful frameworks like &lt;em&gt;React, Vue, and Svelte&lt;/em&gt;, and back-end tools like &lt;em&gt;Node.js&lt;/em&gt;, Javascript isn't just hanging out in the browser anymore—it's running the whole show, front to back. There's literally a JS tool for everything.&lt;/p&gt;
&lt;p&gt;If modern web design were a kitchen, HTML would be the recipe, CSS the presentation on the plate, and Javascript the chef, making the magic happen in real-time. &lt;/p&gt;
&lt;h2 id=&quot;-client-side-vs-server-side-javascript&quot;&gt;&lt;strong&gt; Client-side vs Server-side Javascript&lt;/strong&gt;&lt;/h2&gt;
&lt;h3 id=&quot;client-side-browser-&quot;&gt;&lt;strong&gt;Client-Side (Browser)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;It runs on your Devices . It controls UI and responds to events.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt; - React, Vue, Angular, etc&lt;/p&gt;
&lt;h3 id=&quot;server-side-node-js-&quot;&gt;&lt;strong&gt;Server-Side (Node.js)&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;It runs on a remote server ️. It handles data, APIs and back-end logic.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt; - Express, NestJS, etc&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Core Javascript  lays the foundation, and all the frameworks and libraries ️ build on top of it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;-challenges-and-limitations&quot;&gt;&lt;strong&gt;⚠️ Challenges and Limitations&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;It's not all sunshine and syntax.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt; – Cross-site scripting can be nasty ️&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Browser quirks&lt;/strong&gt; – Some browsers love being &lt;em&gt;extra&lt;/em&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Messy code&lt;/strong&gt; – Write it clean or watch your app turn into spaghetti &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance issues:&lt;/strong&gt; Heavy scripts can slow your site down to turtle speed &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging hell:&lt;/strong&gt; Sometimes finding that one missing semicolon feels like searching for a needle in a haystack &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But hey, every hero has their flaws—Javascript's just keeping things spicy ️.&lt;/p&gt;
&lt;h2 id=&quot;-the-future-of-javascript&quot;&gt;&lt;strong&gt; The Future of Javascript&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Javascript isn't going anywhere except everywhere&lt;/em&gt;&lt;/strong&gt;. It's growing wiser, faster, and maybe just a little weirder (in a good way). Here's what's cooking:&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;Web Assembly (Wasm):&lt;/strong&gt; Javascript's hitting the gym. With Wasm, it's teaming up with languages like Rust and C++ to tackle tasks it was never built for, such as hardcore gaming, video editing, and heavy-duty number crunching — all in your browser. JS + Wasm = power couple of the web.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;TypeScript:&lt;/strong&gt; Javascript's awkward teen years are over. TypeScript is helping it adult properly, giving it types, better tooling, and fewer &quot;undefined is not a function&quot; moments.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;AI and Smart Tooling:&lt;/strong&gt; Development tools are becoming increasingly intelligent. Imagine writing code and your editor gently whispering, &quot;Hey, you forgot a semicolon… again.&quot; AI-assisted coding (hello, Copilot and beyond) is making Javascript dev life faster, easier, and slightly creepier.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;Framework Wars 2.0:&lt;/strong&gt; React, Vue, Svelte, Solid, Qwik, and friends are all pushing the boundaries of fast, reactive UI. The future is about smarter rendering, less Javascript shipped to the browser, and fewer &quot;why is my page load 3MB&quot; moments.&lt;/p&gt;
&lt;p&gt;⚙️ &lt;strong&gt;Server-side Evolution:&lt;/strong&gt; Node.js, Deno, Bun — everyone's racing to make server-side Javascript faster, leaner, and cooler. Serverless functions and edge computing are making it possible to run Javascript anywhere... even on a fridge (probably).&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;Universal Everything:&lt;/strong&gt; Full-stack Javascript is now the norm. Front-end, back-end, mobile apps, desktop apps, even IoT — all running Javascript. Pretty soon, your toaster  might be sending JSON logs  straight to your console ️—because even breakfast needs debugging .&lt;/p&gt;
&lt;h2 id=&quot;-conclusion&quot;&gt;&lt;strong&gt; Conclusion&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Javascript isn't just code&lt;/em&gt;&lt;/strong&gt;—it's the spark that makes the web come alive ⚡. Without it, your site is basically a mannequin in a shop window . But with Javascript? Boom—now you've got Iron Man flying across your screen .&lt;/p&gt;
&lt;p&gt;So go ahead, crack open that browser console .&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Build stuff ️. Break stuff . Fix stuff . Repeat .&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's the Javascript way .&lt;/p&gt;
</description>
<category>Getting Started</category>
<guid isPermaLink="true">https://coderlegion.com/4623/what-is-javascript-and-how-it-powers-modern-websites</guid>
<pubDate>Tue, 12 Aug 2025 12:21:13 +0000</pubDate>
</item>
</channel>
</rss>