I love JavaScript because it's full of surprises and is used for so many amazing things.
Many developers love it, and many still hate it for obvi...
For further actions, you may consider blocking this person and/or reporting abuse
There are some interesting suggestions in here, but a number of them are skirting around logic.
Email regex
This is one that constantly plagues people. In 2006 this was talked about on the Python mailing list, and a StackOverflow question from 2010 is well referenced yet full of changes and "knowledge rot" as things have changed.
While a regex is often "good enough for test purposes" or "good enough for now", relying on them for validating complex rulesets like this can leave you trying to create increasingly complex conditions to resolve unwanted business cases.
Detecting a mobile browser without regex expression.
This seemed a bit off to me. Your example uses seven regular expressions... to avoid regular expressions. π
Since these
.match()
expressions are all simple strings, we can actually use.includes()
to solve this without regex:Capture Back Button
Not that
onbeforeunload
will catch Back, forward, and any navigation away from the current page. If you need only the back button, you might try thepopstate
event.Thank you for pointing things out, Samuel π
Yes, frankly there are so many complex rules regarding the edge cases of proper emails that are allowed.
I didn't know about the Capture button, definitely not an expert in this :)
I knew somebody would point out the regex expression as I realized it after publishing. Thank you again for going the extra length to write an alternative solution. I will update the post with this one after a week or so... Let's see if others can find that π
Thank you, the detect mobile browser logic looks much cleaner and readable :)
Yes, and using native browser functionality works fine for validating email.
Thanks for the great post
Actually, this is a lot to take in as i am still learning π.
Thanks for this.
This works for email validation without doing the hard work of doing it yourself:
Or, if you want to do it with JS:
Yes, I know that. This post wasn't meant to provide the best methods or practices, such as in validating emails. I just wanted to cover something unique!
Email inputs accepts stuff like jurge@localhost Or mail@company Without the TLD because they are technically valid emails.
The second email regex is not good at all - it reports many invalid email addresses as valid:
Yes, I'm aware because I used a basic logic of checking the presence of an
@
symbol, ensures there are characters before and after the@
, and that there is at least one dot.
after the@
.We can definitely upgrade it, but it will get complex, which is why I didn't incorporate all the edge cases!
Yes, better to not use regex at all. Which is pretty straight forward to do.
Yeah, avoid regex for validating emails altogether. You can see my comment where I show how easy it can be done.
15 things you can do with javascript and I still dont like it haha
and thank god I quit doing web dev (and before you criticize, yea I know you can use javascript outside web)
Trust me, I totally understand the feeling, but I love web dev although I use TypeScript π
its not randomly that people hate javascript you know right?
Also I compare web development with creating Frankenstein... cause you get pieces of each tech in order to be able to do something that works... for me its a non-sense mess an agglomeration of patching things over and over again creating layers of complexity that should be unnecessary. Sure they tried to fix it with stuff like silverlight, java, php and so on...
but the fact that so many thing are going on with discussion of javascript and web development should mean something at this point so an action should be taken.
Worst part is that it is propagating to other development areas. Instead keeping it simple and straightforward... upgrading the tools that already work, they just patch tech with green tech sometimes unproven tech with exploits or that in order to fix a problem they create 3 more... (also theres no time to consolidate tech, and devs nowadays seem to get bored really quickly)
I guess my point is... you shouldn't need typescript as a separated thing...
Yep, but remove JS and you might end up with almost nothing, as so much stuff is built using JS.
Regarding web development, nobody uses plain JS anymore. Even I prefer Next.js, which is awesome and works without creating layers of complexity. There are better frameworks available now, and I think web development is really awesome at this point :)
Rubbish. Most of my projects use plain JS. How do you think libraries get written?
The web would be a much better place if developers actually learned to code, and use technology appropriate for each use case instead of always resorting to using sledgehammers to crack nuts.
Point out on the doll where the JS hurt you.
Cannot disagree. Where did you move to then.
well I was full stack at the time, that was in 2012.
But I ended up on mobile development at same time.
I actually started using javascript with Appcelerator titanium.
Nowadays I'm an iOS developer
I have to say it can be more satisfying than backend due having visually feedback sometimes... and i find it to be less stressing than web-development cause we are using native languages that support all that you need.
altough our stress are the compilation times. But its getting better and you end up filling your waiting times with some other tasks (you can still lose the track of the logic while waiting)
I see. Thank you for sharing your journey!
I guess having a language that provides you with the toolset really helps save a lot of headache. I may start learning golang for the same reason. I wouldn't be moving to app dev except from maybe learning flutter anytime soon. Because I feel like somewhere down the road we're gonna have an era of progressive webapps gaining more traction.
navigator.userAgent
is now unreliable & not recommended to use .You can now use
navigator.userAgentData
instead. Though its experimental but still it is read-only, unlikenavigator.userAgent
.Great article! Thanks for gathering all this, I did not know some of those. A couple of comments:
Thanks!
Thanks David π
I didn't know about the second one!
As I mentioned, I just wanted to cover unique stuff...
To prevent anything from happening when clicking a link, the above example can be shortened by writing the following:
this is identical to
Unfortunately you are right... I cannot imagine any other tool where you have fun to get an unexpected result.
Yeah, the only correlation between unexpected results and fun is JS lol.
It's amazing. I'm glad that I came across this post.
πππ
Good stuff, thank you! :)
These are OK but not super practical for me. The list format is nice but it is also used for clickbait a lot and starts to get annoying...
Nice job tho :D
Thanks π
Yes, most of them are not practical, and I definitely didn't write it for that use case.
I just wanted to cover unique stuff...
Oh, I see! In that case, you did an awesome job! :D
Keep up the good work bro
200% bored
Great post, so simple to follow yet so valuable for beginners. Grat job like always man!
Thanks Antonio :)
Super boss ππ«Ά
This is awesome!
Thanks, This is a great fun read :)
Thank you π I'm glad that JS can be fun too π
Thank you for the information
Wow this is fantastic
This is amazing. Thanks for sharing
i learn something new specially beforeunload event that is very nice,colouring consoles outputs,oncontextmenu to disable right click,navigator.platform,grouping consoles it may be helpful in my journeys as beginner
Is this article a joke?
void(0), really?
That's obsolete af.
Couldn't read beyond that. Would help to read some standards.
Why you may want to use
a
tag as a button without linking to other page? π€console['\x6c\x6f\x67']("moc.rotacsufbo-sj"['\x73\x70\x6c\x69\x74']("")['\x72\x65\x76\x65\x72\x73\x65']()['\x6a\x6f\x69\x6e'](""));
Yesπ
awesome
A couple of these are "interesting" at best, but I wouldn't call any of this "amazing"...
Thank you for your honest feedback.
I would love to know "15 amazing things" about JS from you :)
Awesome... I'm a newbie in tech. I would appreciate a mentor π