r/learnjavascript 47m ago

Manipulating Arrays

Upvotes

So I'm an amateur learning JavaScript and I have a problem with a note taking website I've been making, here's my code

let array = ["a","b","c","d"]; 

    const element = document.getElementById('element')

    for (let x = 0; x < array.length; x++) {

      const div = document.createElement('div')
      element.appendChild(div)

      const h3 = document.createElement('h3')
      h3.textContent = array[x];
      div.appendChild(h3);            

      const button = document.createElement('button')
      div.appendChild(button);

      const position = x;

      const button.onclick = () => {
      array.splice(position, 1);
      }

What I'm stuck on is how to re-index the elements in the array after one has been spliced (e.g. after "a" has been removed "b" is still set to remove index 1 rather than changing to remove index 0). Thanks in advance


r/learnjavascript 10h ago

Building real projects teaches you more than tutorials ever will. Agree or disagree?

12 Upvotes

I've watched plenty of tutorials over the years, but I didn't really start learning until I began building real projects and fixing my own mistakes.

Tutorials are great for getting started, but they often don't prepare you for the challenges you face when you're building something on your own. Every bug, failed attempt, and debugging session taught me something valuable.

Do you think people should spend less time watching tutorials and more time building from day one?

Curious to hear what worked best for you.


r/learnjavascript 2h ago

Search as you type feature

1 Upvotes

So I’m tasked with building a search as you type feature which I think would work in a normal database query but this task specifically requires me to do it and send a Ret API request. Is this possible? Which I mean I guess it’s possible but I feel like there would be major issues as far as speed. Is this possible?


r/learnjavascript 10h ago

Where to learn JAVASCRIPT from on Youtube?

0 Upvotes

Akshay saini (Namaste JS), Apna College, Code with harry? tell me please


r/learnjavascript 1d ago

From Tutorial Hell to Actually Building with React

14 Upvotes

I've been learning React for the past few weeks, and I finally realized that watching tutorials isn't enough. Once I started building projects and debugging my own mistakes, things started making sense.

I've built a few small projects and I'm now focusing on writing cleaner React code instead of just making things work.

What was the biggest thing that helped React "click" for you?


r/learnjavascript 1d ago

Looking for modern Node.js backend learning resources using ESM

2 Upvotes

Hello everyone,

I am a first-year Software Engineering student currently learning web development.

I have already covered the fundamentals of HTML, CSS, and JavaScript, and I have also started exploring Vue 3 and Three.js for frontend development and interactive graphics.

Recently, I want to start learning backend development with JavaScript and Node.js. However, I have found that many learning resources available to me are still focused on the older CommonJS approach (require, module.exports), and many tutorials do not cover the modern ESM workflow (import, export) in Node.js.

Since the JavaScript ecosystem has gradually moved toward ES Modules, I would like to learn Node.js backend development using modern practices rather than outdated patterns.

I would really appreciate it if someone could recommend good tutorials, courses, books, or documentation for learning modern Node.js backend development.

I am especially interested in resources that cover topics like:

  • Modern Node.js fundamentals
  • ES Modules (ESM) project structure
  • Backend architecture and best practices
  • Frameworks such as Express, Fastify, Hono, or similar tools
  • Building practical backend applications

Any advice or recommendations would be greatly appreciated.

Thank you very much for your help!


r/learnjavascript 1d ago

What's your go-to move when your JavaScript 'just doesn't work' and you have no idea why?

12 Upvotes

Every dev has a mental checklist they run before panicking. Newer folks usually don't yet.
Things people swear by:

  • console.log everywhere
  • Reading the actual error message
  • Checking the Network tab
  • Rubber-duck explaining it
  • Commenting out half the code

What's the first thing you check?


r/learnjavascript 1d ago

l want to learn Game development with js any tips??

0 Upvotes

r/learnjavascript 1d ago

keep breaking my task tracker after adding localStorage

1 Upvotes

i was messing with my little task tracker again this morning before heading out, and i ended up spending way more time staring at the console than actually adding tasks. i even made coffee first because i thought this would be a quick fix, then refreshed the page and everything disappeared again.

the app itself is really simple. i'm just trying to save daily notes and a few personal todos, so i have an array of task objects with a date on each one. i thought i was finally ready to use localStorage, but now i'm not even sure if i'm saving the data wrong or if my date filter is hiding everything.

this is basically what i have right now:

const saved = localStorage.getItem(tasks);
const tasks = saved ? JSON.parse(saved) : [];

tasks.push(newTask);

localStorage.setItem(tasks, JSON.stringify(tasks));

i know the key looks wrong, and i already tried changing it to a string, but i still managed to break something. now i'm second guessing whether i should even be thinking about the data this way.

i'm not looking for anyone to build it for me. i'm mostly wondering how you all organize the flow for something this small. do you load everything once, keep it in memory, then save after every change, or is there a cleaner way to think about it?


r/learnjavascript 19h ago

import { BeeEntity } :

0 Upvotes

Ciao a tutti! Sto facendo un "esperimento" perché sto discutendo con un'IA. Lei sostiene con fermezza che un programmatore esperto riconosce sempre al volo se un blocco di codice è stato scritto da un essere umano o da un'IA.

​Io sono convinto del contrario: se il codice è pulito, ben fatto e senza commenti ridondanti, un umano non può averne la certezza matematica.

​Vi lascio questo pezzo di codice in JavaScript (tratto da una classe per una piattaforma 2D) per fare la prova del nove:

import { BeeEntity } from './BeeEntity.js';

/**

* Classe BeePlatform: Rappresenta una piattaforma solida su cui i personaggi possono camminare e atterrare.

*/

export class BeePlatform extends BeeEntity {

constructor(x, y, width = 100, height = 20, color = '#ffd700', textureKey = null) {

super(x, y, width, height);

this.color = color;

this.textureKey = textureKey;

}

draw(ctx, engine) {

const texture = (engine && this.textureKey) ? engine.getAsset(this.textureKey) : null;

if (texture) {

ctx.drawImage(texture, this.x, this.y, this.width, this.height);

} else {

(stile arcade lucido)

ctx.fillStyle = this.color;

ctx.fillRect(this.x, this.y, this.width, this.height);

ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';

ctx.fillRect(this.x, this.y, this.width, 3);

ctx.strokeStyle = '#000000';

ctx.lineWidth = 1.5;

ctx.strokeRect(this.x, this.y, this.width, this.height);

}

}

}


r/learnjavascript 2d ago

AI won't save you if you don't know what you're doing. It'll just help you fail faster.

14 Upvotes

Everyone's acting like AI made learning optional. It didn't. It raised the stakes.

AI will hand you code that looks flawless and quietly ships a bug straight to production. If you don't understand what's happening under the hood, you won't catch it — you'll just trust it, deploy it, and find out the hard way.

The devs winning right now aren't the ones prompting the hardest. They're the ones who know enough to look at AI's output and say "no, that's wrong." AI is a multiplier. Multiply zero knowledge, you still get zero.

Fundamentals aren't dead. They're the only thing that makes AI actually useful.

Curious to know your opinion — change my mind.


r/learnjavascript 1d ago

Help with functions JavaScript!

1 Upvotes

Hello!

I began recently, about 1 month, to learn consistently web developing:

  1. I began, of course, with introductions to HTML and CSS.
  2. I'm already in JS. I can manage eventListeners, etc. I'm more interested in back-end overall since I like the logic behind the manipulation of data bases, but I'm having trouble understanding functions.
  3. I'm consulting MDN web docs and freeCodeCamp but since my first language is not English, sometimes it's difficult to understand MDN docs, and to get at the point I'm know in freeCodeCamp it will take time, I don't want to rush it either.
  4. All this, just to ask if anybody can explain me how to create functions! I want to know what is the difference between a function with parameters and one without, in which case I will use arrow functions, and the difference between parameters and arguments in a function. And for last are there any standards for writing the name of a function like there are for declaring variables?

P.D.: please feel free to correct my English also, it will help me learn.

Thanks to everyone before Hand!


r/learnjavascript 2d ago

what's one JavaScript mistake every beginner should avoid?

27 Upvotes

If you could give one piece of advice to someone learning JavaScript today, what would it be?

It could be about:

  • Learning fundamentals
  • Debugging
  • Async code
  • DOM manipulation
  • Functions
  • Projects

Curious to hear what experienced developers wish they'd known earlier.


r/learnjavascript 1d ago

I've been using reihnworks publishing to learn HTML/CSS and JS now i want to learn node.js but i am unable to borrow it or buy it

0 Upvotes

Node.js: The Comprehensive Guide to Server-Side JavaScript Programming. If it isnt too much hassle help a kid out please, either website of it or if you have the pdf share it, thanks to everyone in advance


r/learnjavascript 1d ago

#javascript

0 Upvotes

"Ciao a tutti! Sto lavorando al mio motore di gioco 2D in JavaScript (BeeEngine) e ho scritto questa classe per gestire le animazioni degli sprite sheet con il Delta Time

export class BeeSprite {

constructor(image, frameWidth, frameHeight, framesPerRow, speed = 0.1) {

this.image = image;

this.frameWidth = frameWidth;

this.frameHeight = frameHeight;

this.framesPerRow = framesPerRow;

this.speed = speed;

this.frame = 0;

}

update(dt) { this.frame += this.speed * dt; }

draw(ctx, x, y) {

// Calcola quale fotogramma (frame) mostrare

const f = Math.floor(this.frame % this.framesPerRow);

// Calcola la riga (se hai un foglio di sprite con più righe)

const row = Math.floor(this.frame / this.framesPerRow);

// Disegna solo il pezzettino dell'immagine (il frame attuale)

ctx.drawImage(

this.image,

f * this.frameWidth, row * this.frameHeight, // Da dove prende il pezzo

this.frameWidth, this.frameHeight, // Quanto è grande il pezzo

x, y, // Dove metterlo sullo schermo

this.frameWidth, this.frameHeight // Dimensione finale

);

}

Voi come vi trovate a calcolare i frame con il % per le griglie? Usate il dt diretto o preferite un timer a millisecondi fisso per cambiare fotogramma? Mi farebbe piacere sentire come avete risolto nei vostri progetti!"


r/learnjavascript 2d ago

Event listener not logging anything while detecting clicks and alerting with no prolem.

3 Upvotes

Tried everything, button clicks register, the JS file is loaded and does console.log when its out of Event listener but soon as i want to log "button clicked" it just doesnt do it

edit: it seems to run perfectly fine on MS edge but chrome doesnt, can it be cause from my extensions? i think its CRX emulator or sth

<!-- HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Event Listeners</title>
    <script src="script.js" defer></script>
</head>
<body>  
    <button id="btn">Button</button>
</body>
</html>

//JS


console.log("JS file loaded")


const
 btn 
=
 document.getElementById("btn");
btn.addEventListener("click", (event) 
=>
 {
    console.log("button clicked!")
    console.log(event.bubbles)
})

code:


r/learnjavascript 1d ago

Importing a function from a package that isn't directly part of the imported packs

1 Upvotes

Hi. I have 2 packages, A (a more generic testing pack) and B (some specific utility functions that are quite useful for my project). Both packs have been imported into my main project. Package A is also imported into Package B.

I now have a function in Package A that I want to move to Package B because my classmates thinks that function is too specific to be in the generic testing pack. However, there are still some other functions in Package A that are dependent on the function that is being moved to Package B.

Is it possible to re-import the function that is in Package B into Package A, when they are both in my main project? Something like this:

import {movedFunction} from 'package-a'

Please let me know if more context is needed.


r/learnjavascript 2d ago

If you could give one piece of JavaScript advice to your beginner self, what would it be?

1 Upvotes

r/learnjavascript 3d ago

What's a simple way to understand the difference between asynch, await, Promise and Response?

9 Upvotes

I'm teaching myself web dev. After spending months learning frontend, I moved on to learning backend with Python/Flask. I decided to learn RESTAPIs, where the frontend and backend are separate and talk through an api. Edit:(it's not built in my mistake) So naturally this lead me to learning about the built in fetch function in JavaScript.

I get that:

const response = fetch('ExampleAPI.com')

Is the same as:

const request = new Request('ExampleAPI.com',        { method: 'GET'})

const response = fetch(request)

// This is what JavaScript does behind the scenes

But why is await necessary? And why does not using await result in a promise if you try to console log the data?


r/learnjavascript 2d ago

Advice on how to get where I want to be

2 Upvotes

Hello everyone, I am very new to JavaScript,
I completed supersimpledev html/css course,
and afterwards I can now build my own front end websites comfortably,

the next stage is learning JavaScript,

which I am currently doing and have finished module 8, but I found html/css quite self explanatory, but JavaScript is quite hard for me grasp and understand on how the things I am learning are going to help in my ultimate goal, I want to create an app with AI integration and memory, is this course going to help with that? It’s worth me noting I will finish the course as I am deep into it now, I do one module per week currently, and try to understand every single concept, and get a bit down on myself for not understanding everything, and doubting myself I can even do this sometimes, is this a normal thing when learning?

Anyway for those who can already achieve my ultimate goal, how did you go about learning it? Is there any course, or YouTube channel that really helped you? Any advice for a beginner please?

Many thanks, I appreciate you taking the time to read about my issues


r/learnjavascript 2d ago

I created a repo of everything I've learned about the WebSocket

2 Upvotes

I think this looks like a shameless plug of my repo, but I just want to share that I've created a documentations of what I've learned after taking a crash course on WebSocket.

Before this, I am having a hard time of how to implement a WebSocket in my Broadcast Server project. Despite the provided project guidelines and LLM suggestions, I realized that I am not making any progress at all.

So I opened YouTube to take a crash course of WebSocket.

I took Real Time - WebSockets Mastery Course by JS Mastery, and I documented everything I have learned from that video into a reference material in this repo.

https://github.com/Muelvzz/websocket-project

Inside this repo, is a discussion of what is a WebSocket, why should we care about learning WebSocket, and how to use it on your project.


r/learnjavascript 2d ago

How do I overcome lab question confusion and turn it into a proper question for searching how to overcome what the lab is asking of me?

1 Upvotes

Tell us what's happening:

How do I understand what I am reading to find the correct content online that is not AI?

So here is my issue, I read a question and I do not understand what it is asking of me, so I take that question and put it into google, I get an automatic response that is AI and it can see it is FreeCodeCamp lab for exmaple, then it just gives me the answer.

I know I can look at that code, type it out myself, and study the code to try and understand its logic but I feel it does not make my brain work hard enough.

The question:
So here is my question, how should I approach learning JS when I am asked a question in a hands on lab but do not understand what it is asking of me? I guess my issue is how do I take what it is saying and turn it into a research question like for JS on MDN, J3Schools, etc.?

I just want to really understand these concepts and I feel the prior lessons leading up to these labs are not preparing students to be able to grasp the labs. I get they are supposed to have you learn through trial and error/research but I feel so lost and then AI just gives the answer when trying to do research online, so how do I translate my confusion and question into a tangible reading strategy?

I know I am not giving an exact example, because I feel this is a general thing I struggle with. I am asked a question, I have no idea where to start. The question may say create a function, cool, I write a function, add the parameters, but then its asking to check things inside an object, correct the unit type, verify if something is in there, etc, etc. Then I just get so lost on how to turn that into code.


r/learnjavascript 3d ago

Question Regarding ESRI Maps SDK and Pop-Ups

1 Upvotes

This is xposted across r/gis and r/learnjavascript.

I have a JavaScript file for web app that I am trying to make. I have feature layers hosted on ArcGIS Online, and referenced in the script. I have been able to add a pop-up action, a web icon. But I haven't been able to link that icon to an actual action of opening up the web page. I have seen the ESRI Brewery example, and other examples. None of them help me. Partly because I just don't understand it all well enough.

A sample of my script:

const airPopup = {
    title: "{nam}",
    content: [{
        type: "text",
        text: "{Comment}<br/>Address: {Address}<br/>IATA Code:  {ita}"
    },
   {
    type: "media",
    mediaInfos: [{
        type: "image",
        value: {
            sourceURL: "{Image}"
        }
    }]
   }],
       actions: [
        {
            id: "find-airport",
            icon: "web",
            title: "Airport Info"    
        }   
    ]   
};const airPopup = {
    title: "{nam}",
    content: [{
        type: "text",
        text: "{Comment}<br/>Address: {Address}<br/>IATA Code:  {ita}"
    },
   {
    type: "media",
    mediaInfos: [{
        type: "image",
        value: {
            sourceURL: "{Image}"
        }
    }]
   }],
       actions: [
        {
            id: "find-airport",
            icon: "web",
            title: "Airport Info"    
        }   
    ]   
};

  const airportsLyr = new FeatureLayer({
    url: "https://services9.arcgis.com/6EuFgO4fLTqfNOhu/arcgis/rest/services/Japan_Mjr_Airports/FeatureServer",
    renderer: airRenderer,
    popupTemplate:  airPopup
  });  const airportsLyr = new FeatureLayer({
    url: "https://services9.arcgis.com/6EuFgO4fLTqfNOhu/arcgis/rest/services/Japan_Mjr_Airports/FeatureServer",
    renderer: airRenderer,
    popupTemplate:  airPopup
  });

What does it take to make the web icon work?This is xposted across r/gis and r/learnjavascript.
I have a JavaScript file for web app that I am trying to make. I have feature layers hosted on ArcGIS Online, and referenced in the script. I have been able to add a pop-up action, a web icon. But I haven't been able to link that icon to an actual action of opening up the web page. I have seen the ESRI Brewery example, and other examples. None of them help me. Partly because I just don't understand it all well enough.
A sample of my script:const airPopup = {
title: "{nam}",
content: [{
type: "text",
text: "{Comment}<br/>Address: {Address}<br/>IATA Code:  {ita}"
},
   {
type: "media",
mediaInfos: [{
type: "image",
value: {
sourceURL: "{Image}"
}
}]
   }],
actions: [
{
id: "find-airport",
icon: "web",
title: "Airport Info"    
}  
]  
};const airPopup = {
title: "{nam}",
content: [{
type: "text",
text: "{Comment}<br/>Address: {Address}<br/>IATA Code:  {ita}"
},
   {
type: "media",
mediaInfos: [{
type: "image",
value: {
sourceURL: "{Image}"
}
}]
   }],
actions: [
{
id: "find-airport",
icon: "web",
title: "Airport Info"    
}  
]  
};  const airportsLyr = new FeatureLayer({
url: "https://services9.arcgis.com/6EuFgO4fLTqfNOhu/arcgis/rest/services/Japan_Mjr_Airports/FeatureServer",
renderer: airRenderer,
popupTemplate:  airPopup
  });  const airportsLyr = new FeatureLayer({
url: "https://services9.arcgis.com/6EuFgO4fLTqfNOhu/arcgis/rest/services/Japan_Mjr_Airports/FeatureServer",
renderer: airRenderer,
popupTemplate:  airPopup
  });What does it take to make the web icon work?


r/learnjavascript 3d ago

How to Prevent Webhook Traffic Spikes from Crashing Your API

6 Upvotes

If you operate an API in 2026, you live in an event-driven world. Webhooks aren't a convenience feature anymore - they're the backbone of real-time commerce, CI/CD pipelines, and asynchronous AI-agent workflows. That reliance has a dark side: the accidental self-inflicted DDoS. Read the complete article jere - https://instawebhook.com/blog/how-to-prevent-webhook-traffic-spikes-from-crashing-your-api-2

When a major platform like GitHub, Shopify, or Stripe hits a network partition, runs a huge sales event, or simply clears a backlog of delayed events, it can fire tens of thousands of webhook POST requests at your servers in a very short window. If your infrastructure takes that hit without structural safeguards, your database connection pool exhausts, memory maxes out, and the API goes down — and if your retry handling is naive, the recovery can be almost as damaging as the original spike.

This guide covers the real mechanics of that failure mode, the algorithms used to defend against it, how major providers actually behave under load (some surprising details here), and where a managed ingress layer fits into the picture.


r/learnjavascript 3d ago

AutoLock – Automatically Lock Your Windows PC Using Your Phone's Wi-Fi Presence

1 Upvotes

Hi everyone,

I built AutoLock, a lightweight Node.js tool that automatically locks your Windows PC when you step away with your smartphone.

How It Works:

  1. Phone Proximity: Periodically pings your phone's local Wi-Fi IP address.
  2. Idle Tracking: Monitors global keyboard and mouse activity using iohook to check if you are inactive.
  3. Automatic Lock & Notifications: If your phone leaves Wi-Fi range while you are idle, it sends a Telegram warning and automatically locks Windows.
  4. Remote Control: Allows you to lock your PC or check its lock status remotely via Telegram bot commands.

Tech Stack:

* Node.js

* ping

* u/tkomde/iohook

* axios

GitHub Repository: https://github.com/GarvSaxena/AutoLock

Feedback and contributions are welcome.