11

I wrote the following comment in a programming forum:

Objects in JavaScript behave similar to a regular associative array.

This is how I would use the word "similar" in normal conversation. However, the dictionary says that "similar" is an adjective, and "similarly" should be used in this context instead:

Objects in JavaScript behave similarly to a regular associative array.

Both constructions look grammatically correct to me, but the second one sounds weird. Searching the internet, I see both "behaves similar to" and "behaves similarly to" are used.

So are both considered grammatically correct?

5
  • 5
    Personally, I would phrase it "behave like". BTW, you want to say "associatIVE array" (not "associate array").
    – Dan Bron
    Aug 11, 2014 at 20:15
  • @DanBron - Oh good catch. Aug 11, 2014 at 20:17
  • i would not use like in this case. "behave like" can mean "behave exactly like" (at least to a programmer), and that is not the intent here.
    – user428517
    Aug 11, 2014 at 20:17
  • Related: english.stackexchange.com/q/83110 But there is a problem with this whole idea. The behavior of X might be similar to Y’s behavior, but X’s behavior is not similar to Y. It is similar to Y’s.
    – tchrist
    Aug 12, 2014 at 1:16
  • I think if we start pulling threads here, the cloth unravels. Objects don't really behave, they're acted upon. And one could argue they are a type of associate array, not similar to one (religious wars start in 3... 2...).
    – jimm101
    Mar 7, 2020 at 14:32

2 Answers 2

14

In casual speech you can probably get away with similar, but you may sound uneducated to some. Similarly is the correct adverb form, and it does not sound weird. I would always write similarly in this case. The same is true for different and differently.


As a side note, this sentence lacks subject-verb agreement:

Objects in JavaScript behaves similarly to a regular associate array.

It should be:

Objects in JavaScript behave similarly to regular associate arrays.

(Also, the correct term is associative array)

4
  • Thanks for clarifying it (and correcting my sentence too.) Aug 11, 2014 at 20:48
  • @Derek朕會功夫 But you are in good company. Apple's motto is Think Different.
    – WS2
    Aug 11, 2014 at 23:24
  • 2
    This doesn’t work. They behave similarly to how something else behaves. They do not behave similarly to something else, because that does not make sense.
    – tchrist
    Aug 12, 2014 at 1:13
  • 1
    @tchrist if you understood the intended meaning (i think you did), it makes sense. i agree your example would be considered "more correct" in a writing class or other formal setting, but what i wrote still makes sense.
    – user428517
    Oct 6, 2015 at 15:46
0

The correct word in this usage is similarly.

In a hypothetical situation where there is a test for similarity, and two object are, when tested, found to be similar, then one could say either object behaves similar to the other. There is no such "similar to" test defined in JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.