Thursday, 3 January 2013

Previous Interview Question Next Interview Question
Home

What is a variable in javascript?

Variables in JavaScript are similar to the variables you may have studied in high school algebra.
You can think of variables as "holding places" where values are stored and retrieved. Each holding place has a unique name, which is any combination of letters and numbers that does not begin with a number. (In JavaScript, the characters a-z, A-Z, and the underscore character "_" are all considered to be unique letters.)
Unlike other programming languages, where variables can only hold certain types of data, JavaScript variables are typeless. This means that any variable can take on any type of data -- numbers, strings, arrays, objects, etc. Because JavaScript variables are not restricted to specific types of values, there is no need to "declare" them before using them. Instead, memory is automatically allocated to store the variable when the variable is assigned its first value.
The following JavaScript statement creates a variable named greeting and uses it to store the value "hello":
greeting = "Hello";
The variable greeting can now be used in expressions that produce additional values. For example, the following JavaScript statement shows how to modify greeting's value so that it contains an even friendlier greeting:
greeting = greeting + ", my friend.";
When this statement is executed, the value of greeting changes from "Hello" to "Hello, my friend."

Previous Interview Question Next Interview Question
Home

0 comments :

Post a Comment