Friday, 25 August 2017

JavaScript Datatypes - W3Tricks

JavaScript Datatypes


  • JavaScript allows you to defined with three primitive data types.
  1. Numbers, eg. 123, 120.50 etc. 
  2. Strings of text e.g. "This text string" etc. 
  3. Boolean e.g. true or false.
  • JavaScript also defined two secondary data type.
  1. null.
  2. undefined.

  • JavaScript is also supported object data types. 
  • like Array and etc, discuss in a separate topic.

Syntax

// Numbers Data Type syntax

var numb = 123;

// Strings Data Type syntax

var str = "This is String Data";

// Boolean Data Type syntax

var bol = true;



NOTE -

  • javascript variable defined with ' var ' keyword.
  • Syntax - var keyword variable name = value;

  • javascript is select automatic variable type.

  • javascript is a case sensitive language.
  • Now var name and var Name both are different.
  • Var name and var NAME also both are different.

List of Reserved Words of JavaScript

  • They can't be used as JavaScript variables

Rule of Defined javascript variable

  • Not use JavaScript reserved keywords as a variable name like a loop, In, Do etc...
  • The variable name starts with alphabet (a-z and A-Z) and ' _ ' symbol.
  • The variable name does not start number and any special symbol.

Defined JavaScript variable Syntax

var 1name;    //  not valid. it is start with number.

var *name;  // not valid. it is start with special symbol.

var _name; // it is valid.

var name;  // it is valid.


Variable Scope in JavaScript - Global and Local

  • Global- A global variable is life all program.
  • To access global variable in all program.

  • LocalA local variable is a life with an inside of Scope.
  • To only access inside of function and block.

Variable Scope - Syntax

<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">

var name = "Global";

function data(){
var name = "Local";
document.write(name);
}
data(); // call local
document.write("<br / >" + name); //call global
</script>
</head>

<body>
<h2>W3Tricks - JavaScript</h2>
</body>

</html>

Output


List of Reserved Words of JavaScript

1
abstract
2
boolean
3
break
4
byte
5
case
6
Catch
7
Char
8
Class
9
Const
10
Continue
11
Debugger
12
Default
13
Delete
14
Do
15
Double
16
Else
17
Enum
18
Export
19
Extends
20
FALSE
21
Final
22
Finally
23
Float
24
For
25
Function
26
Goto
27
If
28
Implements
29
Import
30
In
31
Instanceof
32
Int
33
Interface
34
Long
35
Native
36
New
37
Null
38
Package
39
Private
40
Protected
41
Public
42
Return
43
Short
43
Static
43
Super
43
Switch
43
Synchronized
43
This
43
Throw
43
throws
43
transient
43
TRUE
43
Try
43
typeof
43
Var
43
Void
43
volatile
43
While
43
With

0 comments:

Post a Comment