code-style: Is inline initialization of JS objects ok?

Posted by michael on Stack Overflow See other posts from Stack Overflow or by michael
Published on 2010-02-03T06:07:36Z Indexed on 2010/04/04 17:03 UTC
Read the original article Hit count: 303

I often find myself using inline initialization (see example below), especially in a switch statement when I don't know which case loop will hit. I find it easier to read than if statements.

But is this good practice or will it incur side-effects or a performance hit?

for (var i in array) {
    var o = o ? o : {};  // init object if it doesn't exist
    o[array[i]] = 1;     // add key-values
}

Is there a good website to go to get coding style tips?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about coding-style