loading...
Cover image for Share a quick tip you learned about web dev this year

Share a quick tip you learned about web dev this year

urielbitton profile image Uriel Bitton ・1 min read

Hey everyone! Let's share one tip that we learned recently, whether its about javascript, html, css, react, etc. So beginners and even pros can learn something that they didn't before!

Tip

In JavaScript, Use event.stopImmediatePropagation() method to stop actions from a child element to bubble up to the parent.

So if for eample both parent and child execute a different action, clicking on the child element will execute its action and the action of its parent as well. Thus, by using event.stopImmediatePropagation() we can effectively prevent that.

You can comment your tip below

Can't wait to hear all of yours!

Discussion

markdown guide
 

Adaptive loading is one thing I learned that really stands out

For whatever reason when I read that post it really blew my mind.

 

Awesome. Thanks for sharing Ben!

 

Oooh, I know a good one!

copy() on Chrome DevTools (other browsers probably) adds to your clipboard anything you use as an argument.

That gets really powerful when you use it with "Store as global variable". That way you can log a huge server response, for instance, and copy it from the Dev Tools console.

Here's an example:

image

 

I use this all the time when I want to quickly do some web scraping on-the-fly. A little bit of Array#map chaining can easily automate what would have been million Ctrl + Cs.

 
 

nice one! i'll remember this one :)

Thanks for sharing

 

I recently found an article describing online/offline detection. It's as easy as:
window.addEventListener('online', () => console.log('online'))
Works for 'offline' events too. You could also check for 'navigator.onLine'

 
 

Don't exhaust yourself. Take it easy and stay focused

 

This was learnt from my own mistake. Don't use flexbox for everything. If you do, there's performance and code clarity considerations. Think about whether position: absolute can solve the problem just as well.

 

When would you prefer position: absolute over flexbox? For centering/aligning I almost allways use flexbox, also over text-align: center. Absolute positioning I use for pseudo elements or floating alerts for example.

 

My logic is, if something can be done with position: absolute, do it with it. Otherwise, flexbox is ok. With position: absolute you have a lot of freedom: you can center, you can put the element almost anywhere you want and make it behave like you want based on screen size. I think absolute position is often underused. Flexbox, although flexible, might get a bit complicated and will likely reduce your performance. I created a WYSIWYG editor once, whose ancestors were all flexbox. Remember, flexbox has to relayout and repaint if any of its content changed. So, because of that, if you had a lot of content, editing it was unbearably slow and laggy after typing every character.

With position: absolute you can center as well, although not as cleanly, but you can get used to it:

.element {
   top: 50%;
   left: 50%;
   transform: translateX(-50%) translateY(-50%);
}
 

Mistakes sometimes turn out to be gold !
Nice and thanks for sharing :)

 

The one thing I want to share here is that it is not related to web development but jobs and works that is related to any kind of development job.

It does not matter how good a learner, strong committer, hard worker, and effective value adder, the company or organization that you are applying or working will appreciate skills that are only required by that organization.

The thing is that how many courses you have completed or how good grades you have achieved in the studies, the organizations and the recruiters will be looking for someone who has the experience of 3-5 years and someone perfect so that they can get high results in a small amount of time.

There are a few companies and organizations that are aiming to train individuals so that they can become good and professional individuals, and also they are not looking forward to creating a strong and beneficial asset for their organization as well.

 

i totally agree with this. Thanks for sharing!

 
 

I learned that it is always important to use label, title, aria-label or aria-labelledby along with input fields in forms, in order to be accessible by screen readers and assistive technologies.

 

Very true its becoming increasingly important to add those!

 

you can clone an array in javascript with [...Array] thank you for mr awais for this i dont know his dev.to username but wherever you are thanks

 

Can you show an example of how you would do that in javascript?

Thanks for sharing!

 

really? that was super simple bro

//lets say you have an array like this
let animal=['panda','cat','mongoose'];

//then if you want to clone it one of the method i copy from mr awais is this one
let animalClone=[...animal]

as simple as that

Sweet. Definitely useful! Thanks

i found it here the original post

You can do the same with objects. Keep in mind, this doesn't deep clone. So if you intend to change the values in any way, you'll still be mutating the pointer, and by consequence, the original object.

 

Pointers aren't always a good idea!