Dollar Sign Character

Share

What is the Dollar Sign Character?

The dollar sign character ($) is a character of text that has special meaning in some programming languages.

Usage Examples

PHP

In PHP, ALL VARIABLES start with a dollar sign.

$foo = make_foo($bar);

Bash

In Bash, $ is used to use a variable, but not do define it.

foo=bar
echo $foo

Javascript

In Javascript & Typescript, $ isn't part of the language, but it's an alias for jQuery defined when the library is used.

const $p = $('p');
const $also_p = jQuery('p');

The code above works like the modern Javascript built-in document.querySelectorAll.

You may notice that some variables in Javascript start with a dollar sign ($). That doesn't mean anything in the language, it's merely a convention followed by jQuery programmers to prefix the value returned by jQuery with a dollar sign.

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *