JS Variables and Data Types
JavaScript Variables and Data Types
JavaScript Data Types
In JavaScript there are the following types of data:
- String data type. Are strings between apostrophes or quotation marks.
- Numbers data type. Are data type integer or decimal.
- Boolean data type. There are two boolean values: true and false.
Description | Example |
---|---|
String | “String example” or ‘String example’ |
Numbers | 35, -35, 36.50 |
Boolean | true or false |
JavaScript Variables
The variables are declared in JavaScript with the keyword var.
- In JavaScript is not required to declare a variable type. You need to write just the variable name. Variable type will be given after an assignment.
<script type="text/javascript"> <!-- var a; var b; //--> </script> |
- In JavaScript you can declare several variables in the same var, but the statements must be separated by commas.
<script type="text/javascript"> <!-- var a, b, c; //--> </script> |
- When you declare a variable in JavaScript, you can assign an initial value the declared variable.
<script type="text/javascript"> <!-- var a = "Result"; var b; b = 100; document.write(a); document.write("="); document.write(b); //--> </script> |
Result |
---|
Result = 100 |
JavaScript Reserved Words:
These are JavaScript reserved words and can not be used as names of functions, objects or methods.
abstract boolean break byte case catch char class const continue debugger default | delete do double else enum export extends false final finally float for | function goto if implements import in instanceof int interface long native new | null package private protected public return short static super switch synchronized this | throw throws transient true try typeof var void volatile while with |