skip to Main Content

I was watching a video about object literals in JS. Then the guy in the video did something like this:

var Facebook = {
    name: 'Facebook',
    ceo: {
        firstName: "Mark",
        favColor: "Blue"
    },
$stock: 110
};

My question is why is there a $ sign in front of stock? Is there a special meaning? or did he just use it for naming purpose only? I entered $ in console and got something like this:
function $(selector, [startNode]) { [Command Line API] }

I understand that $ sign is used as a selector for JS libraries like JQuery, but what is it’s significance in pure JS?

2

Answers


  1. The $ has no special meaning in JavaScript. It’s just a valid variable name. See this answer.

    Login or Signup to reply.
  2. It’s just a character. If you saw something in the console it’s because some script loaded by that page assigned it a value and it was still in the global scope.

    Sometimes (like with jQuery or Angular) it can get used by convention to denote that the value assigned to that variable or property is related to those libraries somehow.

    In your example it’s just the name of a property.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search