For AI agents: a documentation index is available at https://idratherbewriting.com/llms.txt. Markdown versions of all pages are available by appending .md to any page URL.

Search results

JavaScript: Variables

When you start writing advanced JavaScript code that contains a lot of complex information, you need a way to simplify and manipulate the information. JavaScript uses variables to simplify the statements and work with information. The variables act as containers to hold values.

You list the variables before the statements, like this:

var area = 4000;
var size = 200;

In this case, area is a variable, and its value is assigned to be 4000. size is also a variable, with a value of 200.

You can also list multiple variables by separating the variables with commas on the same line, like this:

var area = 4000, size = 200, distance = 100;

Sponsored

Variables must be one word and can contain both letters and numbers (but can't start with numbers).

If the variable stores text (such as a phrase), the text is called a string. Strings are enclosed in quotes.

var welcome = "Welcome to the application.";

Single quotes are also acceptable instead of double quotes, but you must be consistent. You can't start with a double quote and end with a single quote.

About Tom Johnson

Tom Johnson

I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, agent skills, tech comm careers, and more. Check out my AI courses for more on the latest in AI and tech comm. If you're looking for info about documenting APIs, see my API documentation course.

If you're a technical writer and want to keep on top of the latest trends in tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me.

Finally, I want to note a couple of things. I usually write the first drafts of my posts myself and then use AI to improve accuracy, clarity, and detail in places, so my writing is a mix of human and AI. (Hopefully that's not too off-putting.) Also, the opinions I express on my blog are my own perspectives, not those of my employer.