JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
JavaScript Values are composed of:
- literals. Fixed values are called literals.
- Numbers(with or without decimals) : Example: 10.5 (or) 10
- Strings(within " or ' quotes).
- A number in quotes is treated as text : Example: "hello" (or) 'hello'
- the + operator is called the concatenation operator when on Strings.
- If you put a number in quotes, the rest of the numbers will be treated as strings, and concatenated. Example below:
- <p>The result of adding 2 + 3 + "5":</p>
- <p id="demo"></p>
- <p id="demo2"></p>
- <script>
- var x = 2 + 3 + "5";
- document.getElementById("demo").innerHTML = x;
- var x = "2" + 3 + 5;
- document.getElementById("demo2").innerHTML = x;
- </script>
- O/P : The result of adding 2 + 3 + "5":
55
235
- variables. Variable values are called variables. used to store data values.JavaScript uses the var keyword to declare variables. var keyword tells browser to create variables. An equal (=) is used to assign values to variables. Example: var x;x = 6;
- Numbers(with or without decimals) : Example: 10.5 (or) 10
- Strings(within " or ' quotes).
- A number in quotes is treated as text : Example: "hello" (or) 'hello'
- the + operator is called the concatenation operator when on Strings.
- If you put a number in quotes, the rest of the numbers will be treated as strings, and concatenated. Example below:
- <p>The result of adding 2 + 3 + "5":</p>
- <p id="demo"></p>
- <p id="demo2"></p>
- <script>
- var x = 2 + 3 + "5";
- document.getElementById("demo").innerHTML = x;
- var x = "2" + 3 + 5;
- document.getElementById("demo2").innerHTML = x;
- </script>
- O/P : The result of adding 2 + 3 + "5":55235
JavaScript Expressions: is a combination of values, variables, and operators, which computes to a value. The computation is called an evaluation.
Example: 5+6
JavaScript Comments( // or between /* and */):
Example: //var x;
JavaScript Identifiers: identifiers are used to name variables (and keywords, and functions, and labels).
* the first character must be a letter, an underscore (_), or a dollar sign ($).
* Numbers and hyphens are not allowed as the first character.
* identifiers are case-sensitive.
JavaScript ignores multiple whitespaces.
JavaScript Keywords: JavaScript keywords are reserved words. Reserved words cannot be used as names for variables.
Examples : break, continue, if, else, function, var, while,debugger,for, return, switch, try, catch, etc
var variable:
- "declaring" a variable. Example: var x; After the declaration, the variable has no value. it has the value of undefined .
- You can declare many variables in one statement. Example: var person = "John Doe", carName = "Volvo", price = 200;
- If you re-declare a JavaScript variable, it will not lose its value. Example: var person = "John Doe"; var person; If This still assigns the value of "John Doe" to variable person .
- "declaring" a variable. Example: var x; After the declaration, the variable has no value. it has the value of undefined .
- You can declare many variables in one statement. Example: var person = "John Doe", carName = "Volvo", price = 200;
- If you re-declare a JavaScript variable, it will not lose its value. Example: var person = "John Doe"; var person; If This still assigns the value of "John Doe" to variable person .
No comments:
Post a Comment