Giter VIP home page Giter VIP logo

Comments (5)

Feodoric avatar Feodoric commented on May 17, 2024

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.

chuanxshi avatar chuanxshi commented on May 17, 2024

@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.

DjebbZ avatar DjebbZ commented on May 17, 2024

I understand. In the last loop iteration, after i-- is evaluated, i equals 0, which is falsy. Can you confirm ?

from javascript-patterns.

antonywu avatar antonywu commented on May 17, 2024

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.

DjebbZ avatar DjebbZ commented on May 17, 2024

Thanks for the answers. Closing since it's been open for a long time.

from javascript-patterns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.