:ﺪﻨﺷﺎﺑ ﺮﯾﺩﺎﻘﻣ ﯼﻭﺎﺣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﻪﮐ ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻒﻠﺘﺨﻣ ﻩﺩﺍﺩ ﻉﻮﻧ 5 ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
ﻪﺘﺷﺭ
ﻩﺭﺎﻤﺷ
ﯽﻟﻮﺑ
ءﯽﺷ
ﺩﺮﮑﻠﻤﻋ
:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﯽﺷ ﻉﻮﻧ 6
ءﯽﺷ
ﺦﯾﺭﺎﺗ
ﻪﯾﺍﺭﺁ
ﻪﺘﺷﺭ
ﻩﺭﺎﻤﺷ
ﯽﻟﻮﺑ
:ﺪﻨﺷﺎﺑ ﺮﯾﺩﺎﻘﻣ ﯼﻭﺎﺣ ﺪﻨﻧﺍﻮﺗ ﯽﻤﻧ ﻪﮐ ﻩﺩﺍﺩ ﻉﻮﻧ 2 ﻭ
null
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺩﺍﺩ ﻉﻮﻧ ﻥﺩﺮﮐ ﺍﺪﯿﭘ ﯼﺍﺮﺑ typeof ﺮﮕﻠﻤﻋ ﺯ
typeof "John"
// Returns "string"
typeof 3.14
// Returns "number"
typeof NaN
// Returns "number"
typeof false
// Returns "boolean"
typeof [1,2,3,4] // Returns
"object"
typeof {name:'John', age:34}
// Returns "object"
typeof new Date()
// Returns "object"
typeof function () {} // Returns
"function"
typeof myCar
// Returns "undefined" *
typeof null
// Returns "object"→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>The typeof operator returns the type of a variable, object, function or expression:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"'John' is " + typeof "John" + "<br>" +
"3.14 is " + typeof 3.14 + "<br>" +
"NaN is " + typeof NaN + "<br>" +
"false is " + typeof false + "<br>" +
"[1, 2, 3, 4] is " + typeof [1, 2, 3, 4] + "<br>" +
"{name:'John', age:34} is " + typeof {name:'John', age:34} + "<br>" +
"new Date() is " + typeof new Date() + "<br>" +
"function () {} is " + typeof function () {} + "<br>" +
"myCar is " + typeof myCar + "<br>" +
"null is " + typeof null;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻪﺟﻮﺗ ﺎﻔﻄﻟ
ﺖﺳﺍ ﺩﺪﻋ NaN ﻩﺩﺍﺩ ﻉﻮﻧ
ﺖﺳﺍ ﯽﺷ ﻪﯾﺍﺭﺁ ﮏﯾ ﻩﺩﺍﺩ ﻉﻮﻧ
ﺖﺳﺍ ﯽﺷ ﺦﯾﺭﺎﺗ ﮏﯾ ﻩﺩﺍﺩ ﻉﻮﻧ
ﺖﺳﺍ ﯽﺷ null ﻩﺩﺍﺩ ﻉﻮﻧ
ﺖﺳﺍ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﺮﯿﻐﺘﻣ ﮏﯾ ﻩﺩﺍﺩ ﻉﻮﻧ
ﺖﺳﺍ ﻩﺪﺸﻧ ﻩﺩﺍﺩ ﺹﺎﺼﺘﺧﺍ ﻥﺁ ﻪﺑ ﯼﺭﺍﺪﻘﻣ ﻪﮐ ﯼﺮﯿﻐﺘﻣ ﻩﺩﺍﺩ ﻉﻮﻧ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﺳﺍ (ﺦﯾﺭﺎﺗ ﮏﯾ ﺎﯾ) ﻪﯾﺍﺭﺁ ﮏﯾ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺎﯾﺁ ﻪﮑﻨﯾﺍ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ
ﺖﺳﺍ ﯽﻓﺎﺿﺍ ﭻﯿﻫ ﻥﻭﺪﺑ ﻭ ﻩﺩﺎﺳ ﻩﺩﺍﺩ ﺭﺍﺪﻘﻣ ﮏﯾ ﻪﯿﻟﻭﺍ ﻩﺩﺍﺩ ﺭﺍﺪﻘﻣ ﮏﯾ
:ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﻪﯿﻟﻭﺍ ﻉﺍﻮﻧﺍ ﻦﯾﺍ ﺯﺍ ﯽﮑﯾ ﺪﻧﺍﻮﺗﯽﻣ typeof
ﻪﺘﺷﺭ
ﻩﺭﺎﻤﺷ
ﯽﻟﻮﺑ
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ
typeof "John" // Returns
"string"
typeof 3.14 // Returns
"number"
typeof true // Returns
"boolean"
typeof false // Returns
"boolean"
typeof x
// Returns "undefined" (if x has no value)→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>The typeof operator returns the type of a variable or an expression.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
typeof "john" + "<br>" +
typeof 3.14 + "<br>" +
typeof true + "<br>" +
typeof false + "<br>" +
typeof x;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﻩﺪﯿﭽﯿﭘ ﻉﻮﻧ ﻭﺩ ﺯﺍ ﯽﮑﯾ ﺪﻧﺍﻮﺗ ﯽﻣ typeof ﺮﮕ
ﺩﺮﮑﻠﻤﻋ
ءﯽﺷ
.ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ null ﻭ ﺎﻫﻪﯾﺍﺭﺁ ،ﺎﯿﺷﺍ ﯼﺍﺮﺑ ﺍﺭ "code class="w3-codespan">typeof
.ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﻊﺑﺍﻮﺗ ﯼﺍﺮﺑ ﺍﺭ "ﯽﺷ" ﻉﻮﻧ<"code class="w3-codespan> ﺮﮕﻠﻤﻋ
typeof {name:'John', age:34} // Returns "object"
typeof [1,2,3,4]
// Returns "object" (not "array", see note below)
typeof null // Returns
"object"
typeof function myFunc(){} // Returns "function"→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>The typeof operator returns object for both objects, arrays, and null.</p>
<p>The typeof operator does not return object for functions.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
typeof {name:'john', age:34} + "<br>" +
typeof [1,2,3,4] + "<br>" +
typeof null + "<br>" +
typeof function myFunc(){};
</script>
</body>
</html>
.ﺪﻨﺘﺴﻫ ﺎﯿﺷﺍ ﺎﻫ ﻪﯾﺍﺭﺁ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺍﺮﯾﺯ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺎﻫ ﻪﯾﺍﺭﺁ ﯼﺍﺮﺑ ﺍﺭ "ﯽﺷ<"co
/ * - + ) ﺎﻫﺭﻮﺗﺍﺮﭘﺍ .ﺖﺳﺍ ﺭﻮﺗﺍﺮﭘﺍ .ﺖﺴﯿﻧ ﺮﯿﻐﺘﻣ ﮏﯾ ﻉﻮﻧ<"code class="w3-codespan>
ﻞﻣﺎﺷ) ﻪﺘﺷﺭ ﮏﯾ ﻪﺸﯿﻤﻫ typeof ﺮﮕﻠﻤﻋ ،ﺎ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻩﺪﻧﺯﺎﺳ constructor ﯽﮔﮋﯾﻭ
"John".constructor
// Returns function String() {[native code]}
(3.14).constructor
// Returns function Number() {[native code]}
false.constructor // Returns
function Boolean() {[native code]}
[1,2,3,4].constructor
// Returns function Array() {[native code]}
{name:'John',age:34}.constructor
// Returns function Object() {[native code]}
new Date().constructor
// Returns function Date() {[native code]}
function () {}.constructor // Returns
function Function(){[native code]}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Properties</h1>
<h2>The constructor Property</h2>
<p>The constructor property returns the constructor function for a variable or an
object.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"john".constructor + "<br>" +
(3.14).constructor + "<br>" +
false.constructor + "<br>" +
[1,2,3,4].constructor + "<br>" +
{name:'john', age:34}.constructor + "<br>" +
new Date().constructor + "<br>" +
function () {}.constructor;
</script>
</body>
</html>
.ﺮﯿﺧ ﺎﯾ ﺖﺳﺍ ﻪﯾﺍﺭﺁ<"code class="w3-codespan> ﮏﯾ ﯽﺷ ﮏﯾ ﺎﯾﺁ ﺪﯿﻤﻬﻔﺑ ﺎﺗ ﺪﯿﻨﮐ ﯽﺳﺭﺮﺑ
function isArray(myArray) {
return myArray.constructor.toString().indexOf("Array") > -1;
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>This "home made" isArray() function returns true when used on an array:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple"];
document.getElementById("demo").innerHTML = isArray(fruits);
function isArray(myArray) {
return myArray.constructor.toString().indexOf("Array") > -1;
}
</script>
</body>
</html>
:ﺮﯿﺧ ﺎﯾ ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﻊﺑﺎﺗ ﮏﯾ ﯽﺷ ﺎﯾﺁ ﻪﮐ ﺪﯿﻨﮐ ﯽﺳﺭﺮﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺮﺗ ﻩﺩﺎﺳ ﯽﺘ
function isArray(myArray) {
return myArray.constructor
=== Array;
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Array Object</h1>
<p>This "home made" isArray() function returns true when used on an array:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = isArray(fruits);
function isArray(myArray) {
return myArray.constructor === Array;
}
</script>
</body>
</html>
ﺮﯿﺧ ﺎﯾ ﺖﺳﺍ a ﯽﺷ ﮏﯾ ﺎﯾﺁ ﻪﮐ ﺪﯾﻮﺷ ﻪﺟﻮﺘﻣ ﺎﺗ ﺪﯿﻨﮐ ﯽﺳﺭﺮﺑ ﺍﺭ ﻩﺪﻧﺯﺎﺳ ﯽﮔﮋﯾﻭ ﺪﯿﻧﺍﻮﺗ ﯽﻣ
function isDate(myDate) {
return myDate.constructor.toString().indexOf("Date") > -1;
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Date Object</h2>
<p>This "home made" isDate() function returns true when used on an date:</p>
<p id="demo"></p>
<script>
const myDate = new Date();
document.getElementById("demo").innerHTML = isDate(myDate);
function isDate(myDate) {
return myDate.constructor.toString().indexOf("Date") > -1;
}
</script>
</body>
</html>
:ﺖﺳﺍ ﺦﯾﺭﺎﺗ ﺩﺮﮑﻠﻤﻋ ﮏﯾ ﯽﺷ ﺎﯾﺁ ﻪﮐ ﺪﯿﻨﮐ ﯽﺳﺭﺮﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺮﺗ ﻩﺩﺎﺳ ﯽﺘﺣ ﺎﯾ
function isDate(myDate) {
return myDate.constructor === Date;
}→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Date Object</h2>
<p>This "home made" isDate() function returns true when used on an date:</p>
<p id="demo"></p>
<script>
const myDate = new Date();
document.getElementById("demo").innerHTML = isDate(myDate);
function isDate(myDate) {
return myDate.constructor === Date;
}
</script>
</body>
</html>
.ﺖﺳﺍ undefined ﺭﺍﺪﻘﻣ ﯼﺍﺭﺍﺩ ،ﺭﺍﺪﻘﻣ ﻥﻭﺪﺑ ﺮﯿﻐﺘﻣ ﮏﯾ ،ﺖﭙﯾ
let car; // Value is undefined,
type is undefined→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>The value (and the data type) of a variable with no value is <b>undefined</b>.</p>
<p id="demo"></p>
<script>
let car;
document.getElementById("demo").innerHTML =
car + "<br>" + typeof car;
</script>
</body>
</html>
.ﺩﺮﮐ ﯽﻟﺎﺧ undefined ﺭﺍﺪﻘﻣ ﻢﯿﻈﻨﺗ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﯼﺮﯿﻐﺘﻣ
car = undefined; // Value is undefined,
type is undefined→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>Variables can be emptied if you set the value to <b>undefined</b>.</p>
<p id="demo"></p>
<script>
let car = "Volvo";
car = undefined;
document.getElementById("demo").innerHTML = car + "<br>" + typeof car;
</script>
</body>
</html>
.ﺩﺭﺍﺪﻧ undefined ﻪﺑ ﯽﻄﺑﺭ ﯽﻟﺎﺧ ﺭﺍﺪﻘﻣ ﮏﯾ
.ﺩﺭﺍﺩ ﻉﻮﻧ ﻢﻫ ﻭ ﯽﻧﻮﻧﺎﻗ ﺵﺯﺭﺍ ﻢﻫ ﯽﻟﺎﺧ ﻪﺘﺷﺭ ﮏﯾ
let car = ""; //
The value is
"", the typeof is "string"→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<p>An empty string has both a legal value and a type:</p>
<p id="demo"></p>
<script>
let car = "";
document.getElementById("demo").innerHTML =
"The value is: " +
car + "<br>" +
"The type is: " + typeof car;
</script>
</body>
</html>
.ﺩﺭﺍﺪﻧ ﺩﻮﺟﻭ ﻪﮐ ﺪﺷﺎﺑ ﯼﺰﯿﭼ ﺖﺳﺍ ﺭﺍﺮﻗ .ﺖﺳﺍ "ﺰﯿﭼ ﭻﯿﻫ" null
.ﺖﺳﺍ ﯽﺷ ﮏﯾ null ﻩﺩﺍﺩ ﻉﻮﻧ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ،ﻪﻧﺎﻔﺳﺄﺘﻣ
.ﺪﺷﺎﺑ null ﺪﯾﺎﺑ .ﺖﺳﺍ ﯽﺷ ﮏﯾ
:ﺪﯿﻨﮐ ﯽﻟﺎﺧ null ﯼﻭﺭ ﺮﺑ ﻥﺁ ﻢﯿﻈﻨﺗ ﺎﺑ ﺍﺭ ﯽﺷ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽ
let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = null; //
Now value is null,
but type is still an object→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<p>Objects can be emptied by setting the value to <b>null</b>.</p>
<p id="demo"></p>
<script>
let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = null;
document.getElementById("demo").innerHTML = typeof person;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﯽﻟﺎﺧ undefined ﯼﻭﺭ ﺮﺑ ﻥﺁ ﻢﯿﻈﻨﺗ ﺎﺑ ﺍﺭ ﯽﺷ ﮏﯾ ﺪﯿﻧ
let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = undefined; //
Now both value and type is undefined→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Objects</h1>
<h2>The undefined Data Type</h2>
<p>Objects can be emptied by setting the value to <b>undefined</b>.</p>
<p id="demo"></p>
<script>
let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = undefined;
document.getElementById("demo").innerHTML = person;
</script>
</body>
</html>
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ ﻭ null ﺪ
typeof undefined
// undefined
typeof null
// object
null === undefined
// false
null == undefined
// true→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>Undefined and null are equal in value but different in type:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
typeof undefined + "<br>" +
typeof null + "<br><br>" +
(null === undefined) + "<br>" +
(null == undefined);
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ true ،ﺪﺷﺎﺑ ﻩﺪﺷ ﺺﺨﺸﻣ ﯽﺷ ﺯﺍ ﯼﺍ ﻪﻧﻮﻤﻧ ﯽ
const cars = ["Saab", "Volvo", "BMW"];
(cars instanceof Array);
(cars instanceof Object);
(cars instanceof String);
(cars instanceof Number);→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The instanceof Operator</h2>
<p>The instanceof operator returns true if an object is an instance of a specified object:</p>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML =
(cars instanceof Array) + "<br>" +
(cars instanceof Object) + "<br>" +
(cars instanceof String) + "<br>" +
(cars instanceof Number);
</script>
</body>
</html>
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻭ ﺪﻨﮐ ﯽﻣ ﯽﺑﺎﯾﺯﺭﺍ ﺍﺭ ﺕﺭﺎﺒﻋ ﮏﯾ void ﺮﮕﻠﻤﻋ
<a href="javascript:void(0);">
Useless link
</a>
<a href="javascript:void(document.body.style.backgroundColor='red');">
Click me to change the background color of body to red
</a>→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The void Operator</h2>
<p>
<a href="javascript:void(0);">Useless link</a>
</p>
<p>
<a href="javascript:void(document.body.style.backgroundColor='red');">
Click me to change the background color of body to red.</a>
</p>
</body>
</html>