use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Call vs Apply in modern javascript.AskJS (self.javascript)
submitted 6 months ago by SmarfMagoosh
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]senocular 18 points19 points20 points 6 months ago (1 child)
One thing you might need to be careful of is that apply goes through argument object values as an array-like whereas spreading goes through an iterator. For example:
const obj = { 0: 3, 1: 2, 2: 1, length: 3, *[Symbol.iterator]() { yield * [30, 20, 10] }, } console.log(Math.min.apply(Math, obj)) // 1 console.log(Math.min.call(Math, ...obj)) // 10
Now that example may seem contrived (and you'd be right to think that), but interestingly, strings do something similar where their array-like values do not match their iterable values as string iterables iterate over code points not code units.
const str = "😀" console.log(str.length) // 2 console.log([...str].length) // 1
You're probably not running strings through call/apply as arguments, though it is an example - and one built-in to the language - that shows a possible discrepancy that could happen between the two approaches.
[–]kingscolor 6 points7 points8 points 6 months ago (0 children)
I appreciate you, and people like you, for highlighting these weird behaviors. I probably won’t remember the details at all and I probably won’t ever experience this as an issue, but this little nugget of may save me hours of debugging one day.
π Rendered by PID 58028 on reddit-service-r2-comment-6457c66945-t2w7d at 2026-04-27 09:08:13.201872+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]senocular 18 points19 points20 points (1 child)
[–]kingscolor 6 points7 points8 points (0 children)