Comments (5)
Agreed with this, seems you are relying on 2 types of trickiness for the i--
examples: 0 being falsy, and i--
returning the value of i
before the decrement operation.
from javascript-patterns.
@DjebbZ @Feodoric problem is, if you try i = i -1
or i -= 1
with an array, it will not return the first item in the array.
from javascript-patterns.
I understand. In the last loop iteration, after i--
is evaluated, i
equals 0
, which is falsy. Can you confirm ?
from javascript-patterns.
Typically, I don't even do i--
, I do --i
instead
Crockford roughly went through the reason with "++" in http://www.youtube.com/watch?v=taaEzHI9xyY&t=50m42s
What makes "++" a special case is that "+" is also used for string concatenation, so I suppose it is easier to make mistake. Coming from C++ world, I don't see it as a big deal. However, both Crockford and I would agree that ++i
and --i
are not the same as i++
and i--
(the former usage is preferred, whereas later should be avoided)
from javascript-patterns.
Thanks for the answers. Closing since it's been open for a long time.
from javascript-patterns.
Related Issues (20)
- Better jQuery Pattern Append HOT 1
- Page doesn't work well on low resolutions HOT 1
- Patterns not consistently used
- Namespace
- Un-responsive design makes content unusable on smaller screens HOT 2
- String concatenation => Better jQuery Pattern Append
- #5
- #1#
- When this conditional expression can be better than anything else?
- Get a maintainer HOT 3
- Count down to zero HOT 1
- can function declaration be named as a pattern? HOT 3
- about self-defining-functions,some issuse not sure
- Define "trickyness" in for-loop pattern HOT 3
- Maintain this repository HOT 14
- New method declaration convention
- Function declarations -- antipattern? HOT 2
- switch pattern indents `case`; breaks its rule #1
- Fixed position nav overlays content HOT 1
- There is no such method in jQuery
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript-patterns.