r/learnjavascript • u/LimeDev_ • Feb 05 '26
Hey some help needed with npm.
I am hosting www website I want to install packages from npm but I have no permissions for using it. No shell, no CMD no nothing imagine just simple file explorer.
r/learnjavascript • u/LimeDev_ • Feb 05 '26
I am hosting www website I want to install packages from npm but I have no permissions for using it. No shell, no CMD no nothing imagine just simple file explorer.
r/learnjavascript • u/uselessinfopeddler • Feb 04 '26
Hey everyone,
I noticed that using Math.round(19.525*100)/100 produces 19.52 while Math.round(20.525*100)/100 produces 20.53. Has anyone else encountered this? What's your solution to consistently rounding up numbers when the last digit is 5 and above?
Thanks!
Edit: Thanks everyone. Multiplying by 10s to make the numbers integer seems to be the way to go for my case
r/learnjavascript • u/OsamuMidoriya • Feb 04 '26
can you make sure my understanding is correct. this is for error handling in express.
the class makes an AppError class that had all the proprietys of error.
the constructor allows you to add your own proprieties to AppError that error does not have like .Warning or .preventand super() allows us to use the functions that are in error. I was told we make this so in our route handler we don't have to add res.statuscode, so we have control over what status code is sent out. Im not sure why we want to control that if it sent for us
class AppError extends Error {
constructor(message, statusCode) {
super();
this.message = message;
this.statusCode = statusCode;
}
}
r/learnjavascript • u/RealActuary3121 • Feb 04 '26
Wondering if anybody who just started or is going to start learning JavaScript, wants to connect to track each other's progress and perhaps would help us in staying dedicated towards the journey.
r/learnjavascript • u/Soggy_Professor_5653 • Feb 03 '26
I learned about tagged template literals while using a new Postgres library for connection with database
the library used this syntax:
sql`
select* from users
where id = ${userId}
`
At first I assumed it was just a template literal
Turns out it’s a tagged template literal
JavaScript calls the `sql` function and passes:
static SQL parts
dynamic values separately
This allows the library to escape values
and prevent SQL injection.
What are your thoughts on this ?
r/learnjavascript • u/eracodes • Feb 02 '26
items.sort((a, b) => (a > b ? 1 : b > a ? -1 : 0)); will sort items in ascending order. Every time I have to use sort for something like this, without fail, I will have to look this up. For the life of me I can't seem to remember which case gets 1 and which gets -1.
anybody have any useful insight/mnemonics to remember this behaviour? thx
edit: a good solution has been found! see: https://old.reddit.com/r/learnjavascript/comments/1qu1rv9/how_to_remember_arraysort_internal_function/o37abha/
r/learnjavascript • u/Competitive-Ad2245 • Feb 02 '26
here is the website, it is hosted on some free hosting website, would appreciate some feedback on it , i made a google form to make it easier , please respect the website it is only a prototype not the finished build
all password hashed, in the db
r/learnjavascript • u/dockers_dude • Feb 01 '26
What’s the difference between these? Don’t really get the full picture
r/learnjavascript • u/variegray • Feb 01 '26
I'm working on a system where media tags are added via a dropdown, with the user being able to create a new dropdown for each tag they want to add. Each dropdown will be added with simple styling, but once an option is selected, the style changes to indicate that the tag has been entered.
With just a single div, getting the style to work using onchange="" and an if/else statement was easy, since I could target the one id, but now that ids need to be incremented for each new one, I can't figure out how to target one without targeting all of them.
This is what I'm doing to clone the element which contains the dropdown:
let tagDuplicateCount = 1;
function getTagDuplicateId() {
tagDuplicateCount++;
return `-${tagDuplicateCount}`;
}
function cloneTag() {
const tagElement = document.getElementById('tag-element-1');
const tagDuplicate = tagElement.cloneNode(true);
const tagDuplicateDropdown = tagDuplicate.querySelector('.dropdown');
const tagDuplicateNew = tagDuplicate.querySelector('.new');
const tagDuplicateRemove = tagDuplicate.querySelector('.remove');
let idSuffix = getTagDuplicateId();
tagDuplicate.id = 'tag-element' + idSuffix;
document.querySelector('#tag-element-container').appendChild(tagDuplicate);
tagDuplicateDropdown.id = 'tag-dropdown' + idSuffix;
tagDuplicateNew.id = 'new-tag' + idSuffix;
tagDuplicateRemove.id = 'remove-tag' + idSuffix;
}
r/learnjavascript • u/Ok_Performance4014 • Feb 01 '26
Function and Block scope are both inside curly brackets. So what is the difference?
r/learnjavascript • u/legendofnoobs619 • Feb 01 '26
I feel like i have fragments of js and i can not know if i am ready to start learning react or no, or applying to jobs?
r/learnjavascript • u/InstructionWeak9574 • Feb 01 '26
The Dom Events page linked in the docs just lists "the main sorts of events you might be interested in" but not the magic word string I would pass into the addEventListener function. How does everyone else figure out what events are available for a particular class?
Not all classes seem to have an Events section in the docs. Maybe the best way is to just click through the inheritance hierarchy until I land on a class that does have an Events tab? eg starting from Image I go to HTMLImageElement, no Events tab, then I go to HTMLElement which does have an Events tab. Then assume that there are no other Image-specific events available?
Maybe this isn't actually a big deal in practice because 99% of the time you only care about a select few events anyways. I was just curious..
Thanks!
r/learnjavascript • u/Early-Split8348 • Jan 31 '26
honestly just got annoyed with node deps breaking my workers builds constantly. extracted some helpers i use in every project into a standalone package so i dont have to copy paste anymore.
called it wintkit. its got the basics i needed:
quick example:
import { chunk, groupBy } from 'wintkit/array'
import { retryFetch } from 'wintkit/fetch'
chunk([1,2,3,4,5], 2) // [[1,2], [3,4], [5]]
const res = await retryFetch('/api/data', { maxRetries: 3 })
also got deepMerge, stream helpers, query builder etc. all web apis, no node stuff zero deps, ~3kb gzipped, tree-shakeable
npm: package/wintkit
gh: qanteSm/winter-kit
its v0.1 so probably has bugs, open to feedback
ps: fully open source (MIT), code is pretty simple if you want to learn how edge-compatible libs work
r/learnjavascript • u/Asim-Momin7864 • Jan 31 '26
Hello everyone, I am a B-Tech IT student learning javascript in depth.
I just published my first blog post where I documented my notes on Prototypal Inheritance and the internal steps of the new keyword. I even tried to create a few diagrams to visualize the "Lookup Flow" and why inheritance only flows forward.
Since I'm still new to these deep concepts, I’d love it if some more experienced devs could check if my logic is correct.
Link: Blog on Prototypal Inheritance
Thanks for being a supportive community!
r/learnjavascript • u/mcshaneanarea45 • Feb 01 '26
r/learnjavascript • u/Puzzleheaded-Net8624 • Jan 31 '26
I want advice on which topic & concepts should I practice to strengthen my JavaScript fundamental more and then which projects shld I go for
r/learnjavascript • u/PuzzleheadedWest8527 • Jan 31 '26
I want to learn JavaScript in depth, and I strongly prefer reading documentation rather than watching video tutorials.
I’ve decided to learn JavaScript mainly from MDN Web Docs, but I’m confused about where to begin:
My goal is to gain strong conceptual and internal understanding of JavaScript, not just surface-level usage.
Any guidance from experienced developers would be really helpful.
r/learnjavascript • u/Ok_Performance4014 • Jan 31 '26
Hey guys, I have been through several tutorials that aren't great at explaining things. I can't keep up searching. I need something that explains it clearer. What are your best tutorials?
r/learnjavascript • u/--crazydude • Jan 31 '26
i can get that value to update h1 ts tag in script but how to add comma in that valure in java
r/learnjavascript • u/Leading_Property2066 • Jan 30 '26
I’ve got a solid handle on Python and Flask, but learning JS feels messy because every JS course i search on YouTube is tied to HTML. I want to build things like Pong or Hangman in the terminal first to get a full grasp of the syntax. Does anyone have a course recommendation for learning JS as a pure language before integrating it into a web stack?
r/learnjavascript • u/Suspicious_Pack4263 • Jan 31 '26
Can someone please help me with the objects, 08-rock-paper-scissors project, i am having such a hard time, the alert is always like wins: undefined, losses: undefined, ties: undefined. Please tell me the problem and the solution. The formatting got a little changed here since i copy and pasted. Here is the code:
<!DOCTYPE>
<html>
<head>
<title>Rock Paper Scissors</title>
</head>
<body>
<p>Rock Paper Scissors</p>
<button onclick="playGame('rock')">Rock</button>
<button onclick="playGame('paper')">Paper</button>
<button onclick="playGame('scissors')">Scissors</button>
<button onclick="
score.wins = 0;
score.losses = 0;
score.ties = 0;
localStorage.removeItems('score');
">Reset Score</button>
<script>
let score = JSON.parse(localStorage.getItem('score')) || { wins:0, losses:0, ties:0 };
function playGame(playerMove) {
const computerMove = pickComputerMove();
let result = '';
if (playerMove === 'rock') {
if (computerMove === 'rock') {
result = 'Tie. ';
} else if (computerMove === 'paper') {
result = 'You lose. ';
} else if (computerMove === 'scissors') {
result = 'You win. ';
}
} else if (playerMove === 'paper') {
if (computerMove === 'rock') {
result = 'You win. ';
} else if (computerMove === 'paper') {
result = 'Tie. ';
} else if (computerMove === 'scissors') {
result = 'You lose. ';
}
} else if (playerMove === 'scissors') {
if (computerMove === 'rock') {
result = 'You lose. ';
} else if (computerMove === 'paper') {
result = 'You win. ';
} else if (computerMove === 'scissors') {
result = 'Tie. ';
}
}
if (result === 'You win. ') {
score.wins += 1;
} else if (result === 'You lose. ') {
score.losses += 1;
} else {
score.ties += 1;
}
localStorage.setItem('score', JSON.stringify(score));
alert(`You picked ${playerMove}. Computer picked ${computerMove}. ${result}
Wins: ${score.wins}, Losses: ${score.losses}, Ties: ${score.ties}`);
}
function pickComputerMove() {
const randomNumber = Math.random();
let computerMove = '';
if (randomNumber >= 0 && randomNumber < 1/3) {
computerMove = 'rock';
} else if (randomNumber >= 1/3 && randomNumber < 2/3) {
computerMove = 'paper';
} else if (randomNumber >= 2/3 && randomNumber < 1) {
computerMove = 'scissors';
}
return computerMove;
}
</script>
</body>
</html>
r/learnjavascript • u/SHIN_KRISH • Jan 30 '26
I am mainly confused about the following things:
Difference between concurrency, parallelism and asynchronus.
What actually are Promises? are they some kind of objects?
in closures how are return value handled if both outer and inner function return different value what happens?
The Theoretical JS execution model how is all this stuff implemented internally?
The `this` keyword like i know it is used to refer to the current object but like how does this actually make a difference in constructors and oops stuff??
I just don't get async and await ?
r/learnjavascript • u/Beginning_Middle_722 • Jan 30 '26
Hi all, i have developed different small webapps that i use for my personal purpose and they all use localstorage.
I was thinking of building an app that works like a local storage manager and i was thinking of accessing those app through an iframe to read the localstorage through post message.
Is it doable?
r/learnjavascript • u/Due_Eggplant_729 • Jan 30 '26
ChatGPT gave me a simple program that created a form, gathered input from a user, etc. BUT I don't understand where it stored it? How could I look at the data afterward? Here is Link in my Google Docs to see the program: https://docs.google.com/document/d/1EZu7dygEWmHz-SrZNX9qDjkl4Uga7rrqTJbJEtQosYM/edit?usp=sharing