Often, as developers, we write similar types of code, falling into a pattern that, while comfortable, can sometimes feel mundane.
However, the wor...
For further actions, you may consider blocking this person and/or reporting abuse
Beware...
x | 0
is not the same asMath.floor(x)
, neither is~~x
- as is sometimes written.They are the same as
Math.trunc(x)
for numbers up to 32 bits. bigger than 32 bits they are different.
developer.mozilla.org/en-US/docs/W...
@mmainulhasan we need more Bitwise operators examples
Nice article. It would bei nice if you included links to the according MDN articles.
Your coclusion bothers me:
eval, with, document.write() and __proto__
don't belong in anyones "toolkit". But: I'd really enjoy an an article named "Javascripts forbidden fruits".If you care about your fellow developers and your future self - reading your Code, you also should avoid Labels, the comma operator, functions in blocks, void and any bitwise operators except for actual Bit Manipulation.
I personally dislike Automatic semicolons, because they might lead to hard-to-find Bugs.
Many aspects of js
mightdefinitely lead to hard-to-find bugs.Aaaah nice, labelled
break
andcontinue
, the fork and spoon of spaghetti code 🍝😄break
isn´t as bad asgoto
, there are situations where it can be most useful and not too much confusing. Adding some flags to break out a loop is not much clearer and has the same effect.But it is worth to mention that in JS break without labels always breaks out to the outermost loop, so using labels can be a real life saver.
one more feature of JS
Memoization for Performance Optimization
Memoization is a technique used to optimize the performance of functions by caching the results of expensive function calls and returning the cached result when the same inputs occur again. This can significantly reduce redundant calculations, especially in recursive or computationally intensive functions.
By memorizing function results, developers can enhance the efficiency of their code, particularly in scenarios where functions are repeatedly called with the same inputs, as it minimizes unnecessary computation. This aligns with the theme of exploring advanced JavaScript features to improve code performance and productivity.
This isn't a feature of JS, rather a general programming technique.
Maybe ...
But there is memoization in Rect to prevent extra rendering with usecallback and use Memo. Maybe this technique is implemented as a feature.
React is built from plain JS
Not a feature of JS itself, just a practice developed over the years, do not confuse
Explained it gre8 though, in easy mode
Fun list, useful too.
I recognise two distinct groups, though:
Thanks for the article! This is fun trip down memory lane of many old features now opposed strongly for daily use. You will see many of them in compiled production code, still.
18 and on are more like the new features that people should definitely know.
Assignment in JS is not a statement unless combined with
var
,let
, orconst
.We use the assignment operator (
=
) to perform the assignment, and that assignment has a value, which is the second operand of the assignment operator (the value being assigned to the variable).It's not that JS 'allows for chained assignments', they are possible as a direct result of the fact that an assignment using the assignment operator has a value, i.e.
a = 2
has a value of2
.So, in your example:
The code sets
c
to the value of5
,b
to the value ofc = 5
(which we know from the value of the assignment is also 5), anda
to the value ofb = c = 5
(which is also 5).Good list, there were a few things I wasn't aware of. That said: #9 and #17 are the same. #3 missed the opportunity of showing a tagged template literal being used, since the setup is just another function, might be glanced over.
When would one ever use "2 -- comma operator" ?
Sometimes in
for
loops:I dont think that is the same. let x = (1, 2); console.log(x); would be using the mentioned feature. But this will just log ‘2’
It's the same feature, you're just not using the return value.
Code golf
Thank you :-)
number #25 is simply a lie
Is not a lie, it's a feature in DevTools 111!
Your code produces an error when used in a
<script>
tag.To reproduce the error in DevTools, try this:
ah, thanks for pointing that out. In any case I dislike very much classes, but I am glad they added the true privacy for properties.
I am more fan for functional programming, factories, pure functions, etc.
To create a private member which is not even visible:
Holy Shot. I’m using comma in swift expressions since for ever and never new it’s possible in js. I will definitely use it now
Unfortunately it’s not like I thought it works in conditions. The last one will be returned. No wonder I did not see it in the wild.
The reason so many are "unnoticeable" is because they're considered bad practice and deprecated from the language.
Nice.
9 and 17 are the same
9 — in Operator for Property Checking
17 — The in Operator for Property Existence
Thanks for sharing
I fail to understand the difference from point 9 and 17:
9 — in Operator for Property Checking
17 — The in Operator for Property Existence
Great list!
Number 3 has no example. I can't tell what you're trying to communicate.
thanks, good article. #1,#2 and #9 are new to me.
awesome dude ,,,
more useful :P
Nice list! I didn't know about a few of these.
they are the same with math.floor
Excellent compilation of features.
1 — Labels for Loop and Block Statements
Was my first impression of this blog