« first day (4065 days earlier)      last day (866 days later) » 

12:49 AM
0
Q: React functional components: edit variable defined in function in a subfunction

AnvaySorry for the bad title. I don't really know how to describe my issue. I have a react functional component. It's meant to be text that you can drag to edit the value. An example is here. To do this, I have 3 nested functions as the event listener callbacks. mouseUp, mouseDown, and mouseDrag. I ha...

 
@Anvay Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
1:10 AM
var l = ['a', 'step 1', 'b', 'step 2']
what's the most concise way to sort l such that the result is ['step 1', 'step 2', 'a', 'b']
Goal is to get all the steps first sorted by step number, then the rest sorted alphabetically
 
 
2 hours later…
3:03 AM
posted on December 02, 2021 by Matt

The Dev channel is being updated to 98.0.4729.0 (Platform version: 14371.0.0) for most Chrome OS devices. If you find new issues, please let us know by visiting our forum or filing a bug. Interested in switching channels Find out how. You can submit feedback using ‘Report an issue...’ in the Chrome menu (3 vertical dots in the upper right corner of the browser).&nb

 
 
2 hours later…
5:29 AM
Hi All
Im using bitly api to shorten the long url, this is working fine. But what I'm also trying to do is, generate different shorten URL for the same long url
to do that, Im concatinating different characters as per my business logic
for example
www.google.com/#02
www.google.com/#03
www.google.com/#04
what is the best way to get a different shorten URL for the same long url
 
5:56 AM
wat
like, just add a number to it
?
what does best mean
 
 
1 hour later…
7:07 AM
@VLAZ [ 'step 2', 'b', 'step 1', 'a' ] Logged: [ ] Took: 64ms
 
||>  ['step 4', 'a', 'step 1', 'b', 'step 2', 'step 3']
.sort((a, b) => {
	const diff = b.startsWith("step") - a.startsWith("step");
	if (Math.abs(diff) !== 0)
		return diff;
  return a.localeCompare(b);
})
 
@VLAZ Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
@VLAZ [ 'step 1', 'step 2', 'step 3', 'step 4', 'a', 'b' ] Logged: [ ] Took: 0ms
 
@duhaime ^
Oops, no need for Math.abs, so it can be shorter.
However, I would still prefer to writ the cases out explicitly
Or if you really hate yourself you could go for even shorter
||>  ['step 4', 'a', 'step 1', 'b', 'step 2', 'step 3']
.sort((a, b) => (b.startsWith("step") - a.startsWith("step")) || a.localeCompare(b))
 
@VLAZ [ 'step 1', 'step 2', 'step 3', 'step 4', 'a', 'b' ] Logged: [ ] Took: 0ms
 
8:00 AM
console.log(typeof typeof 8); Hi can i have a clarification of this million doller question ?
 
@vijay Clarify what, exactly? It returns "string" because typeof returns a string.
 
typeof 5 => it returns "number" isn't ?@VLAZ
 
@vijay And what is the type of the string "number"?
||> typeof "number"
 
@VLAZ 'string' Logged: [ ] Took: 0ms
 
its string
 
8:03 AM
Bingo
 
@vijay Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
1 message moved to Trash can
 
const name = "Rajesh";
if(name === "Rajesh") {
let name = "Kumar";
console.log(name);
var name = "Ravi";
}

console.log(name);
what will be both consoles @VLAZ@JamesBot
 
An error?
 
and why ?
 
||> const name = "Rajesh";
if(name === "Rajesh") {
let name = "Kumar";
console.log(name);
var name = "Ravi";
}

console.log(name);
 
8:07 AM
@VLAZ 'SyntaxError: Identifier \'name\' has already been declared' Logged: [ ] Took: 0ms
 
For the reason the error states.
 
how it can be corrected this to get output
?
 
Don't redeclare the variables. Just in general probably don't use var.
 
okay great and how we can redeclar
?
 
Why do you need to redeclare the variable?
 
8:09 AM
if i want to redeclare for some reason
?
 
I have never found a reason to redeclare a variable within the same scope. It's only "allowed" with var because it's not disallowed. It doesn't actually make sense to ever do it. At least I've never either found sense or been given a sensible answer when I've asked for why.
 
we can do shallow copy instead ?
for (var i = 0; i < 5; i++) {

setTimeout(function() { console.log(i); }, i * 1000 );

}
 
also fixable if you don't use var
 
i can use let ?
 
Yes let i instead of var i
 
 
3 hours later…
11:05 AM
hello can someone help me here: stackoverflow.com/questions/70194700/…
 
@KodeKamper Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
11:20 AM
@VLAZ it's still used by minifiers.
not sure if it is historical or intended. I am leaning towards the latter
but as you said, as an actual use in js code? nope. Unless you want a function-declared variable. In that case, you should question your own design first IMHO
 
12:05 PM
Thank you VLAZ! I'd never used localCompare before
 
 
3 hours later…
2:47 PM
Hi!
 
@RixTheTyrunt Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
Hah, I already know. I'm just here for testing LOL.
 
A_V
Hello, I know this is the wrong place to discuss Grafana/Loki queries but I'm wondering if there's a chat about those kind of things
 
3:00 PM
So wait,
||> console.log("Hullo world")
 
@RixTheTyrunt undefined Logged: [ '"Hullo world"' ] Took: 0ms
 
Hi JS experts, what is the actual difference between string[] vs [] as string[] ?
in Typescript
or do they mean the same?
 
@faceturn look for "type assertion" in TS documentation
it briefly explains what it does and once you understand it, you might have answered your own question
 
3:35 PM
Thanks
 
 
1 hour later…
4:52 PM
@faceturn string[] means you've declared the type to be an array of strings. as string[] means you are asserting that the type is an array of strings. Assertions are a way of overruling the compiler and I'd advise not to use them unless there is no other option.
 
ok thanks @VLAZ
got it
 
5:21 PM
@VLAZ thank you so much... yeah got it... :)
 
IGP
5:44 PM
Does using "same-origin" mode in fetch request have an impact in any way?
 
@IGP Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
@IGP yes
|| mdn same origin
 
That explains what it is; the fetch page explains how it applies
|| mdn fetch
 
IGP
6:19 PM
So far I've only used fetch without touching the mode option for local data. I'm wondering if there is any benefit to being explicit about it by doing adding the line

mode: 'same-origin',

to the fetch options.
 
it's just a safeguard
By specifying same-origin, you cause it to throw an error if in some way someone modifies your code or the environment such that it sends the request to another origin
 
IGP
Sounds like I'm just making my code harder to maintain.
 
eh
by that logic you can say the same about typescript
that by putting safety mechanisms in place it's harder to maintain
when... in actuality, preventing future you from making mistakes, can save you time and effort
 
IGP
Fair enough
 
hi
does anyone know how to scrap likes and dislikes from all avaiable youtube videos?
 
IGP
6:38 PM
dislikes are probably not publicly accessible anymore
Besides your own videos
 
7:00 PM
o/
 
until 13.12 though the youtube data api
 
Is there a youtube music api
 
there are approx. 5 billion videos on youtube
 
Jawed Karim creator/first ever poster went back to his original video last month and changed the description "When youtubers agree that removing dislikes is a stupid idea, it probably is"
 
7:27 PM
imagine trying to "optimize" fetch code without understanding how http requests work
 
@KevinB this concept took me a long time to understand
 
-3
Q: Does making a call to request.text() require await?

fr00z1I am trying to figure out ways to improve site speed. Going on the javascript journey I found how extraneous or unnecessary awaits could bring a site to a crawl. Getting back to the optimization lens, I am trying to figure out if await is really required for use with request.text. My perception: ...

someone actually suggested using synchronous xhr in the comments
!!woosh
 
Invalid command! Did you mean: woosh, choose, woah? Try help for a list of available commands..‍.‍.‍.‍.‍
 
fixit
 
@KevinB XMLHttpRequest isn't sync tho
it doesn't use promises, but it's not sync
 
7:40 PM
it can be, if you pass the param in a browser that hasn't removed it yet
 
IGP
I need help with fetch. Basically, I have this:

fetch(uri, options)
.then(response => throw Error based on (response.ok), otherwise return response.json() )
.catch(error => pass error message to another function );

...The main issue is the error message comes from the backend. Is there a way to access the fulfilled promise in this catch block?
 
so, you're getting response.ok, and then throwing due to an application error?
or what
 
IGP
Swal.fire({
	[...]
	preConfirm: () => {
		return fetch(uri, {
			[...]
			})
			.then(response => {
				if (!response.ok) throw new Error(response.statusText);
				return response.json();
			})
			.catch(error => Swal.showValidationMessage(`Request failed: ${error}`));
	},
})
 
@KevinB ah, didn't even know that existed
 
@IGP i'm still not sure what you're wanting
because, there's only one promise, and if you're in catch, it was rejected either by fetch itself, or by you using throw
 
7:45 PM
@JBis Yes. And it shouldn't. Basically all browsers over the last decade or so have been throwing warnings if you ever use it that it's deprecated and advised not using it. OK, maybe not some of the older IEs (can't really remember if they did or not) but...you know, they were IE.
 
IGP
Well, right now if the fetch request fails, I'll throw an Error with the statusText (Bad Request, Forbidden, Not Found, etc).

The issue is I need to throw the Error with the actual error message that comes from the backend, and I can't access to it without doing response.json() first.
 
I am trying to render this column definition to where if the Notes data source is null, no tooltip shows over that row (the code I tried is what is commented out. But instead of doing what I thought, it is hiding the full data source from the row except for TrainingLink
 
@IGP i'm not entirely sure it's possible
if it is, you'd be able to call response.json() or response.text(), depending on the type of response, even on error
but i half expect it to just not give you access to it
 
@IGP I'm not sure I get what the problem is - if you call .json() the body will always be tried to be serialised as JSON. In a lot of cases, however, if the response is 404 or 500 or another error message, the body is simply not JSON, so parsing it fails. However, if you're sending properly encoded JSON on error, it should work. Otherwise you can try .text() and return whatever the body of the response was without trying to parse it specifically to JSON.
 
IGP
8:01 PM
@VLAZ It's not a case of the response failing unexpectedly. The backend I'm working with provides properly formatted json messages for specific errors.
Anyways I managed to do what I want, but I hate the way it looks.
return fetch(uri, {...})
  .then(response => {
    if (!response.ok) {
      response.json()
        .then(error => {
          throw new Error(error.message)
        })
        .catch(error => {
          Swal.hideLoading();
          Swal.showValidationMessage(`Request failed: ${error}`)
        });
    };
    return response.json();
  });
 

« first day (4065 days earlier)      last day (866 days later) »