Graduated in Digital Media M.Sc. now developing the next generation of educational software. Since a while I develop full stack in Javascript using Meteor. Love fitness and Muay Thai after work.
break isn´t as bad as goto, 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.
Usabilty Engineer and JavaScript/TypeScript Developer. On the path to become a Clean Code Developer. Also rediscovering OOP-Principals and Design-Patterns.
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.
Programming is a major entertainment of my life. I’m interested in learning new technology development concepts and making suggestions for improvement. GitHub: https://github.com/paghar
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.
functionfibonacci(n,memo={}){if (ninmemo)returnmemo[n];if (n<=1)return1;returnmemo[n]=fibonacci(n-1,memo)+fibonacci(n-2,memo);}console.log(fibonacci(10));// Example usage
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.
Programming is a major entertainment of my life. I’m interested in learning new technology development concepts and making suggestions for improvement. GitHub: https://github.com/paghar
JavaScript allows for chained assignments, which can assign a single value to multiple variables in one statement
Assignment in JS is not a statement unless combined with var, let, or const.
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 of 2.
So, in your example:
leta,b,c;a=b=c=5;
The code sets c to the value of 5, b to the value of c = 5 (which we know from the value of the assignment is also 5), and a to the value of b = 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.
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.
Bringing AI & machine learning right to where you are in your workflow. Supercharging tools like GitHub, VS Code, JetBrains, Browsers, and more! Try Pieces for Developers Suite for free today!
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
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.
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.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:
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.
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.
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:
I fail to understand the difference from point 9 and 17:
9 — in Operator for Property Checking
17 — The in Operator for Property Existence
The reason so many are "unnoticeable" is because they're considered bad practice and deprecated from the language.
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.
Nice list! I didn't know about a few of these.
Number 3 has no example. I can't tell what you're trying to communicate.
awesome dude ,,,
more useful :P
Nice.
thanks, good article. #1,#2 and #9 are new to me.
Great list!
9 and 17 are the same
9 — in Operator for Property Checking
17 — The in Operator for Property Existence
Thanks for sharing
1 — Labels for Loop and Block Statements
Was my first impression of this blog
they are the same with math.floor
Excellent compilation of features.