5 JavaScript Tips You Probably Don't Know

preview_player
Показать описание
We do a lot of TypeScript on this channel, but JavaScript is still a growing language, and you can do some pretty cool stuff with JS these days! If it's been a while since you looked at what's new in JavaScript, you might find something new in this video!

#javascript #ecmascript
Рекомендации по теме
Комментарии
Автор

Wouldn't it be possible to create a 2d Array using `Array.from({ length: 5 }, () => [])`?

fagnersales
Автор

2d arrays:
const a = Array.from({ length: 5 }, () => []);

range:
const rangle = (start: number, end: number) => {
const [length, step] = end > start ? [end - start + 1, 1] : [start - end + 1, -1];
return Array.from({ length }, (_, index) => start + index * step);
}

dimitro.cardellini
Автор

I like creating array like this: Array.from({length: 10}, (_, i) => i)

mluevanos
Автор

Oh damn, #4 is really tricky that it behaves the way it does to be honest. I mean maybe not according to the language specification, but I can see a lot of people accidentally slipping before/unless they test their code, myself included.

Thanks for the video, really cool one.

dechobarca
Автор

I am really loving these JavaScript videos. Today everything is about TypeScript and while I love using and learning about it, it sometimes doesn't help you with solving a problem. You need to understand the underlying language (JavaScript) and these videos are helping to learn about some of the more modern features and APIs that JavaScript offers. Then in conjunction with TypeScript, you get superpowers.

Mane
Автор

The array fill caught me off guard once during an interview for a job. I had to do some kind of algorithm, which I actually coded the right way, but I initialized the array like you showed and it screw me over. I learned it the 'hard' way unfortunately ;D

mateuszgroth
Автор

Map and Set, I would love a video about this topic.

JaimeOlmo
Автор

Wow really cool video. I didn't know about a bunch of these additions Andrew. Thanks!

Jambajakumba
Автор

Didnt know you could do this type of thing with bind. Would use it in my code now, probably.

MrREALball
Автор

It's much more performant and better to use `Array.from({ length: 5 }), () => [])`. It's more concise and it only iterates once over the array which is much better for larger arrays. Also, the second argument to Array.from, the initializer function takes 2 arguments, the seconds being the index, so that comes in super handy sometimes too.

todd_matheson
Автор

Completely unrelated, but what is going on with that 'fi' font ligature? Curious that that isn't monospaced but everything else is?

joostschuur
Автор

I am sorry I do not understand the *declare* keyword purpose on line 2 when you explain the _NCO_ @ 2:00 ... or in any other cases where you have been using it in the examples...

Luxcium
Автор

Only the 2d array tip was new for me, but also probably the least useful since I can't remember a time where I ever created a set size 2d array without looping over data that needs to get injected into that array anyway...

DontFollowZim
Автор

5 JavaScript tips... in TypeScript. Great job.

SomewhatLazy
Автор

If you work with immutable data, it won't be a problem to instantiate arrays like this.

majorhumbert
Автор

just wondering when you were a teen if you are from winchester, tn . you look familiar

PickledHam
Автор

Rather than doing new Array(x).fill().map(), I think [...new Array(x)].map() is nicer to read. Don't know the exact performance implications of spread vs fill but I only ever use it for small arrays so I'm sure it's negligible

thematrix
Автор

The title is misleading, The video is about Typescript and not about Javascript.

montebont
Автор

Just stop doing functional and mutate your state

tbigqhb
Автор

>5 JavaScript Tips
Proceeds with TS, dislike

aidemalo