Variables & Operators
JavaScript Data Types:
One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language.
JavaScript allows you to work with three primitive data types:
• Numbers eg. 123, 120.50 etc.
• Strings of text e.g. "This text string" etc.
• Boolean e.g. true or false.
Java does not make a distinction between integer values and floating-point values.
JavaScript Variables:
Variable is the stored memory location that can hold a value in it. Variables are declared with the var keyword. Storing a value in a variable is called variable initialization.
Example:
JavaScript Variable Scope:
The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
• Global Variables: A global variable has global scope which means it is defined everywhere in your JavaScript code.
• Local Variables: A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
JavaScript Variable Names:
While naming your variables in JavaScript keep following rules in mind.
• You should not use any of the JavaScript reserved keyword as variable name.
• JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character.
• JavaScript variable names are case sensitive.
JavaScript Reserved Words:
The following are reserved words in JavaScript. They cannot be used as JavaScript variables,functions, methods, loop labels, or any object names.
Types of Operators: logical, arithmetic, relational
Operators: An Operator is a symbol that performs an operation. JavaScript language supports following type of operators.
• Arithmetic Operators
• Comparision Operators
• Logical (or Relational) Operators
• Assignment Operators
• Conditional (or ternary) Operators
The Arithmetic Operators:
Assume variable A holds 10 and variable B holds 20 then: