1. Datatypes are defined at runtime in javascript.
var x= "str";
console.log(typeof x) //Output String
s=10;
console.log(typeof x) //Output int
2. There are three primitive types in javascript
1. string
2. boolean
3. number
float number is also consider as number.
3. If a variable is not defined anywhere only assigned a value inside function it is assume global by default and it can be accessed outside function
function F1()
{
x=9;
}
F1();
alert(x);
4. According to point 3 it can create problem so avoid this we use 'use strict'. By using this line we can not use a variable without defining it.
'use strict'
function F1()
{
x=9;
}
F1();
alert(x);
This will give error. 'x' is not defined. So in this way x can not be used without defining it so while we define it, it will be local. So can not be used outside F1.
5. In java script declaration is pulled up.
alert(x);
var x=10;
it will run and give message undefined.
alert(x);
Though above code will run so no message will appear. And error will be there.
Null reference error.
6. Immediate invoking function
(function()
{
alert("hi");
}());
var x= "str";
console.log(typeof x) //Output String
s=10;
console.log(typeof x) //Output int
2. There are three primitive types in javascript
1. string
2. boolean
3. number
float number is also consider as number.
3. If a variable is not defined anywhere only assigned a value inside function it is assume global by default and it can be accessed outside function
function F1()
{
x=9;
}
F1();
alert(x);
4. According to point 3 it can create problem so avoid this we use 'use strict'. By using this line we can not use a variable without defining it.
'use strict'
function F1()
{
x=9;
}
F1();
alert(x);
This will give error. 'x' is not defined. So in this way x can not be used without defining it so while we define it, it will be local. So can not be used outside F1.
5. In java script declaration is pulled up.
alert(x);
var x=10;
it will run and give message undefined.
alert(x);
Though above code will run so no message will appear. And error will be there.
Null reference error.
6. Immediate invoking function
(function()
{
alert("hi");
}());
No comments:
Post a Comment