O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining and Accessing Variables

  var x = y = 5;   var z = 10;   var results = "x + y + z = " + (x+y+z);   var s1 = "jQuery";   var s2 = "JavaScript"   var s3 = s1 + " & " + s2;

JavaScript makes it easy to define variables. Variables are assigned using var name = value; syntax. The var keyword tells JavaScript that this is a new variable name. Once the variable has been assigned a value, you can access it using the variable name. You can define multiple variables on a single line using var name1 = name2 = value; syntax.

When you assign a variable to an expression, such as x + y + z, the expression is evaluated before assigning the variable a value. The following code snippet shows you how to define and access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required