User:The Transhumanist/Workshop boilerplate/var

var
This is the reserved word var, which is used to declare variables. A variable is a container you can put a value in. To declare the variable portletlink, write this:

A declared variable has no value, until you assign it one, such as like this:

You can combine declaration and assignment in the same statement, like this:

Caveat: if you assign a value to a variable that does not exist, the variable will be created automatically. If it is created outside of a function, it will have global scope. For user scripts used on Wikipedia, having a variable of global scope means the variable may affect other scripts that are running, as the scripts are technically part of the same program, being called via import from a .js page (.js pages are programs). So, be careful. Here are some scope-related resources:


 * The Horror of Implicit Globals
 * Scope in JavaScript