JS Variables
+2
JasonOmeter
Admin
6 posters
Page 1 of 2
Page 1 of 2 • 1, 2
JS Variables
JavaScript Variables
JavaScript variables are containers for storing data values.
In this example, x, y, and z, are variables:
Example
var x = 5;
var y = 6;
var z = x + y;
From the example above, you can expect:
x stores the value 5
y stores the value 6
z stores the value 11
JavaScript Identifiers
All JavaScript variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
For any clarifications you can leave your comment below.
JavaScript variables are containers for storing data values.
In this example, x, y, and z, are variables:
Example
var x = 5;
var y = 6;
var z = x + y;
From the example above, you can expect:
x stores the value 5
y stores the value 6
z stores the value 11
JavaScript Identifiers
All JavaScript variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
For any clarifications you can leave your comment below.
Re: JS Variables
Tnx for the information Ma'am, i have a question for you maam,
what if i assign value of
var x = "33";
var y = 33;
var x = x + y;
what will be the answer maam? and what is the difference between "33" to 33 without quotation?
what if i assign value of
var x = "33";
var y = 33;
var x = x + y;
what will be the answer maam? and what is the difference between "33" to 33 without quotation?
JasonOmeter- Master
- Posts : 7
Join date : 2017-10-13
Re: JS Variables
JasonOmeter wrote:Tnx for the information Ma'am, i have a question for you maam,
what if i assign value of
var x = "33";
var y = 33;
var x = x + y;
what will be the answer maam? and what is the difference between "33" to 33 without quotation?
Good Evening Jason! Numbers are written without quotes. If you put a number in quotes, it will be treated as a text string. Therefore, if you run the program the answer will be 3333 because the variable you assign in x is treated as a text string it will not be added to 33.
Re: JS Variables
Is the assignment operator included in js variables?
EzequielGo- Master
- Posts : 13
Join date : 2017-10-14
Re: JS Variables
Can I create my own Javascript variable?
SarahMae- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
EzequielGo wrote:Is the assignment operator included in js variables?
Hello Ezequiel Yes dear, the Assignment Operator is included in JavaScript Variables.
Re: JS Variables
SarahMae wrote:Can I create my own Javascript variable?
Hi Sarah! Yes of course! You can create your own JS Variables
Re: JS Variables
Admin wrote:SarahMae wrote:Can I create my own Javascript variable?
Hi Sarah! Yes of course! You can create your own JS Variables
Can you please show me how to create my own javascript variable?
SarahMae- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
Admin wrote:EzequielGo wrote:Is the assignment operator included in js variables?
Hello Ezequiel Yes dear, the Assignment Operator is included in JavaScript Variables.
What is assignment operator?
SarahMae- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
Admin wrote:EzequielGo wrote:Is the assignment operator included in js variables?
Hello Ezequiel Yes dear, the Assignment Operator is included in JavaScript Variables.
Like how? What's the use of assignment operator Ma'am?
EzequielGo- Master
- Posts : 13
Join date : 2017-10-14
Re: JS Variables
SarahMae wrote:Admin wrote:SarahMae wrote:Can I create my own Javascript variable?
Hi Sarah! Yes of course! You can create your own JS Variables
Can you please show me how to create my own javascript variable?
Creating a variable in JavaScript is called "declaring" a variable. You declare a JavaScript variable with the var keyword:, After the declaration, the variable has no value. Technically it has the value of undefined. To assign a value to the variable, use the equal sign:, You can also assign a value to the variable when you declare it:. In the example below, I create a variable called myName and assign the value "Kayganthe" to it.
var myName = "Kayganthe";
Re: JS Variables
SarahMae wrote:Admin wrote:EzequielGo wrote:Is the assignment operator included in js variables?
Hello Ezequiel Yes dear, the Assignment Operator is included in JavaScript Variables.
What is assignment operator?
In JavaScript, the equal sign (=) is an "assignment" operator, not an "equal to" operator.
Re: JS Variables
Can we declare many variables in one statement?
Clyntt- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
Clyntt wrote:Can we declare many variables in one statement?
Yes dear, you can declare many variables in one statement
Re: JS Variables
Admin wrote:Clyntt wrote:Can we declare many variables in one statement?
Yes dear, you can declare many variables in one statement
Can you show me how Ma'am ?
Clyntt- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
Clyntt wrote:Admin wrote:Clyntt wrote:Can we declare many variables in one statement?
Yes dear, you can declare many variables in one statement
Can you show me how Ma'am ?
Just simply start the statement with var and separate the variables by comma. For Example: var person = "Kayganthe", myName = "Kayla", age = 19;
Did you get it?
Re: JS Variables
Admin wrote:Clyntt wrote:Admin wrote:Clyntt wrote:Can we declare many variables in one statement?
Yes dear, you can declare many variables in one statement
Can you show me how Ma'am ?
Just simply start the statement with var and separate the variables by comma. For Example: var person = "Kayganthe", myName = "Kayla", age = 19;
Did you get it?
Yes Maam! Thanks for the information.
Clyntt- Master
- Posts : 9
Join date : 2017-10-14
Re: JS Variables
Anne wrote:Can strings be written in single quote?
Strings are written inside double or single quotes. It does not matter.
EzequielGo- Master
- Posts : 13
Join date : 2017-10-14
Re: JS Variables
SarahMae wrote:Admin wrote:EzequielGo wrote:Is the assignment operator included in js variables?
Hello Ezequiel Yes dear, the Assignment Operator is included in JavaScript Variables.
What is assignment operator?
Same question. What is the use of assignment operator?
Anne- Master
- Posts : 8
Join date : 2017-10-14
Page 1 of 2 • 1, 2
Page 1 of 2
Permissions in this forum:
You cannot reply to topics in this forum
|
|