What is the main Difference between var $name and var name?

Recommended Answers

All 6 Replies

Technically nothing, but the ones with $ usually help to identify jQuery elements easily.

the difference between var $name and var name is that whenever you see a person using $name in his code instead of normal name, avoid talking to him, avoid conversing with him, avoid WORKING with him, and if your girlfriend happens to know him drop her too, even if he's family. Otherwise take on him and make him your slave, the only thing they are good for, anyway :)

Not really. You see, prefixing string-variable names with a certain symbol like $, is not all that bad...
Seeing my uncle do that, would feel quite normal to me. -He is from '70-ties!

But this is JavaScript. :)

LOL. True, but it's an allowed character for a variable, so why not use it if it can help identifying variables easily ;)

:) That's because in JavaScript everything is variable.

Prefixing a variable-name [initially] containing a String (object or literal) with $ symbol - is plain dumb, for who knows what it may become few lines after.

Furthermore JavaScript is a Dynamic Types language, treating it as Static is simply wrong.
A plain literal string depending on a stituation may change its type from string to any other js-type, and that's a beauty of it, it's Alive!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.