ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺘﺷﺭ


فهرست مطالب

    نمایش فهرست مطالب

.ﺪﻨﺘﺴﻫ ﻦﺘﻣ ﯼﺭﺎﮑﺘﺳﺩ ﻭ ﻩﺮﯿﺧﺫ ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺘﺷﺭ

.ﺖﺳﺍ ﻩﺪﺷ ﻪﺘﺷﻮﻧ ﻝﻮﻗ ﻞﻘﻧ ﻞﺧﺍﺩ ﺭﺩ ﻪﮐ ﺖﺳﺍ ﺮﺘﮐﺍﺭﺎﮐ ﺪﻨﭼ ﺎﯾ ﺮﻔﺻ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﮏﯾ

ﻝﺎﺜﻣ

let text = "John Doe";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p id="demo"></p>

<script>
let text = "John Doe";  // String written inside quotes
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﻧﺎﮔﻭﺩ ﺎﯾ ﮏﺗ ﯼﺎﻫ ﻝﻮﻗ ﻞﻘﻧ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

let carName1 = "Volvo XC60";  
  // Double quotes
let carName2 = 'Volvo XC60';  // Single quotes 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<p>Strings are written inside quotes. You can use single or double quotes:</p>

<p id="demo"></p>

<script>
let carName1 = "Volvo XC60"; // Double quotes
let carName2 = 'Volvo XC60'; // Single quotes

document.getElementById("demo").innerHTML =
carName1 + " " + carName2; 
</script>

</body>
</html>


ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﺖﻘﺑﺎﻄﻣ ﺎﻫ ﻝﻮﻗ ﻞﻘﻧ ﺎﺑ ﻪﮐ ﯽﻃﺮﺷ ﻪﺑ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﻞﺧﺍﺩ ﺭﺩ ﺎﻫ ﻝﻮﻗ ﻞﻘﻧ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

let answer1 = "It's alright";
let answer2 = "He is called 'Johnny'";
let answer3 = 'He is called "Johnny"';

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<p>You can use quotes inside a string, as long as they don't match the quotes surrounding the string.</p>

<p id="demo"></p>

<script>
let answer1 = "It's alright";
let answer2 = "He is called 'Johnny'";
let answer3 = 'He is called "Johnny"'; 

document.getElementById("demo").innerHTML =
answer1 + "<br>" + answer2 + "<br>" + answer3; 
</script>

</body>
</html>



ﻪﺘﺷﺭ ﻝﻮﻃ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ length ﯽﻠﺧﺍﺩ ﯽﮔﮋﯾﻭ ﺯﺍ ،ﻪﺘﺷﺭ ﮏﯾ ﻝﻮﻃ ﻥﺩﺮﮐ ﺍﺪﯿﭘ ﯼﺍﺮﺑ

ﻝﺎﺜﻣ

let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<h2>The length Property</h2>

<p>The length of the string is:</p>
<p id="demo"></p>

<script>
let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.getElementById("demo").innerHTML = text.length;
</script>

</body>
</html>



ﺭﺍﺮﻓ ﺖﯿﺼﺨﺷ

:ﺩﻮﺷ ﯽﻣ ﻪﺟﻮﺘﻣ ﻩﺎﺒﺘﺷﺍ ﺍﺭ ﻪﺘﺷﺭ ﻦﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﺪﻧﻮﺷ ﻪﺘﺷﻮﻧ ﻝﻮﻗ ﻞﻘﻧ ﻞﺧﺍﺩ ﺭﺩ ﺪﯾﺎﺑ ﺎﻫ ﻪﺘﺷﺭ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ

let text = "We are the so-called "Vikings" from the north.";

.ﺖﺳﺍ ﻩﺪﺷ ﺩﺮﺧ "ﺡﻼﻄﺻﺍ ﻪﺑ ﺎﻣ" ﻪﺑ ﺪﺷ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ

.ﺖﺳﺍ ﺶﻠﺳﺍ ﮏﺑ ﺭﺍﺮﻓ ﻪﺴﯾﻮﻧ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،ﻞﮑﺸﻣ ﻦﯾﺍ ﺯﺍ ﯼﺮﯿﮔﻮﻠﺟ ﯼﺍﺮﺑ ﻞﺣ ﻩﺍﺭ

:ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﻪﺑ ﺍﺭ ﺹﺎﺧ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ escape (\) ﺶﻠﺳﺍ ﮏﺑ ﻪﺴﯾﻮﻧ

Code Result Description
\' ' Single quote
\" " Double quote
\\ \ Backslash

:ﺪﻨﮐﯽﻣ ﺩﺭﺍﻭ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ ﺍﺭ ﯽﯾﺎﺗﻭﺩ ﻝﻮﻗ ﻞﻘﻧ ﮏﯾ \" ﻪﻟﺎﺒﻧﺩ

ﻝﺎﺜﻣ

let text = "We are the so-called \"Vikings\" from the north.";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>The escape sequence \" inserts a double quote in a string.</p>

<p id="demo"></p>

<script>
let text = "We are the so-called \"Vikings\" from the north.";
document.getElementById("demo").innerHTML = text; 
</script>

</body>
</html>

:ﺪﻨﮐ ﯽﻣ ﺝﺭﺩ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ ﺍﺭ ﻝﻮﻗ ﻞﻘﻧ ﮏﯾ \' ﻪﻟﺎﺒﻧﺩ

ﻝﺎﺜﻣ

let text= 'It\'s alright.';

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>The escape sequence \' inserts a single quote in a string.</p>

<p id="demo"></p>

<script>
let text = 'It\'s alright.';
document.getElementById("demo").innerHTML = text; 
</script>

</body>
</html>

:ﺪﻨﮐﯽﻣ ﺩﺭﺍﻭ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ ﺍﺭ ﺶﻠﺳﺍ ﮏﯾ \\ ﻪﻟﺎﺒﻧﺩ

ﻝﺎﺜﻣ

let text = "The character \\ is called backslash.";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>The escape sequence \\ inserts a backslash in a string.</p>

<p id="demo"></p>

<script>
let text = "The character \\ is called backslash.";
document.getElementById("demo").innerHTML = text; 
</script>

</body>
</html>

:ﺪﻨﺘﺴﻫ ﺮﺒﺘﻌﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺮﮕﯾﺩ ﺭﺍﺮﻓ ﻪﻟﺎﺒﻧﺩ ﺶﺷ

\b

ﺲﯿﭙﺳﺍ ﮏﺑ

\f

ﻡﺮﻓ ﺪﯿﻓ

\n

ﺪﯾﺪﺟ ﻂﺧ

\r

ﻪﻟﻮﻤﺤﻣ ﺖﺸﮔﺮﺑ

\t

ﯽﻘﻓﺍ ﻝﻭﺪﺟ

\v

ﯼﺩﻮﻤﻋ ﺮﮕﻟﻭﺪﺟ

ﺪﻧﺩﻮﺑ ﻩﺪﺷ ﯽﺣﺍﺮﻃ ﻝﺮﺘﻨﮐ ﯼﺍﺮﺑ ﺍﺪﺘﺑﺍ ﺭﺩ ﻻﺎﺑ ﺭﺍﺮﻓ ﺖﯿﺼﺨﺷ 6


ﺪﮐ ﯽﻧﻻﻮﻃ ﻁﻮﻄﺧ ﻦﺘﺴﮑﺷ

ﺪﻨﻨﮐ ﯼﺭﺍﺩﺩﻮﺧ ﺮﺗ ﯽﻧﻻﻮﻃ ﺪﮐ ﻁﻮﻄﺧ ﺯﺍ ﺪﻧﺭﺍﺩ ﺖﺳﻭﺩ ﺐﻠﻏﺍ ﻥﺎﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ،ﯽﯾﺎﻧﺍﻮﺧ ﻦﯾﺮﺘﻬﺑ ﯼﺍﺮﺑ

ﺖﺳﺍ ﻦﺘﺴﮑﺷ ﯼﺍﺮﺑ ﻥﺎﮑﻣ ﻦﯾﺮﺘﻬﺑ ،ﺩﺮﯿﮕﻧ ﺭﺍﺮﻗ ﻂﺧ ﮏﯾ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﻮﺘﺳﺩ ﺮﮔﺍ

ﻝﺎﺜﻣ

document.getElementById("demo").innerHTML =
"Hello Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Statements</h2>

<p>
The best place to break a code line is after an operator or a comma.
</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
"Hello Dolly!";
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﺍﺪﺟ ﺶﻠﺳﺍ ﮏﯾ ﺎﺑ ﯽﻨﺘﻣ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ ﺍﺭ ﺪﮐ ﻂﺧ ﮏﯾ ﺪﯿﻧﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ

ﻝﺎﺜﻣ

document.getElementById("demo").innerHTML = 
"Hello \
Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>
You can break a code line within a text string with a backslash.
</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello \
Dolly!";
</script>

</body>
</html>

ﺪﻨﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯾﺍ ﺎﻫﺮﮔﺭﻭﺮﻣ ﯽﺧﺮﺑ
.ﺪﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﯽﻧﺎﻬﺟ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺖﺳﺍ ﻦﮑﻤﻣ .ﺖﺴﯿﻧ ﯽﺤﯿﺟﺮﺗ ﺵﻭﺭ \

ﺖﺳﺍ ﻪﺘﺷﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،ﻪﺘﺷﺭ ﮏﯾ ﻦﺘﺴﮑﺷ ﯼﺍﺮﺑ ﺮﺗ ﻦﺌﻤﻄﻣ ﻩﺍﺭ ﮏﯾ

ﻝﺎﺜﻣ

document.getElementById("demo").innerHTML = "Hello " + 
"Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>The safest way to break a code line in a string is using string addition.</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello " +
"Dolly!";
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﺍﺪﺟ ﺶﻠﺳﺍ ﮏﺑ ﮏﯾ ﺎﺑ ﺍﺭ ﺪﮐ ﻂﺧ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ

ﻝﺎﺜﻣ

document.getElementById("demo").innerHTML = \ 
"Hello Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Statements</h2>

<p id="demo">You cannot break a code line with a \ backslash.</p>

<script>
document.getElementById("demo").innerHTML = \
"Hello Dolly.";
</script>

</body>
</html>

ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺘﺷﺭ

:ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻆﻔﻟ ﺯﺍ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﯾﺍﺪﺘﺑﺍ ﺮﯾﺩﺎﻘﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺘﺷﺭ ،ﻝﻮﻤﻌﻣ ﺭﻮﻃ ﻪﺑ

let x = "John";

:ﺩﺮﮐ ﻒﯾﺮﻌﺗ ﺰﯿﻧ new ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺎﻫ ﻪﺘﺷﺭ ﺎﻣﺍ

let y = new String("John");

ﻝﺎﺜﻣ

let x = "John";
let y = new String("John");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p id="demo"></p>

<script>
// x is a string
let x = "John";

// y is an object
let y = new String("John");

document.getElementById("demo").innerHTML =
typeof x + "<br>" + typeof y;
</script>

</body>
</html>

.ﺪﯿﻨﮑﻧ ﺩﺎﺠﯾﺍ Strings ءﺎﯿﺷﺍ

.ﺪﻫﺩ ﯽﻣ ﺶﻫﺎﮐ ﺍﺭ ﺍﺮﺟﺍ ﺖﻋﺮﺳ ﻭ ﺪﻨﮐ ﯽﻣ ﻩﺪﯿﭽﯿﭘ ﺍﺭ ﺪﮐ new ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

:ﺪﻨﻨﮐ ﺩﺎﺠﯾﺍ ﯼﺍ ﻩﺮﻈﺘﻨﻣﺮﯿﻏ ﺞﯾﺎﺘﻧ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﯼﺍ ﻪﺘﺷﺭ ءﺎﯿﺷﺍ

:ﺪﻨﺘﺴﻫ ﺮﺑﺍﺮﺑ==، x> ﺮﮕﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ

let x = "John";
let y = new String("John");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Never Create Strings as Objects</h2>
<p>Strings and objects cannot be safely compared.</p>

<p id="demo"></p>

<script>
let x = "John";        // x is a string
let y = new String("John");  // y is an object
document.getElementById("demo").innerHTML = (x==y);
</script>

</body>
</html>

:ﺪﻨﺘﺴﯿﻧ ﺮﺑﺍﺮﺑ===، x> ﺮﮕﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ

let x = "John";
let y = new String("John");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Never Create Strings as Objects</h2>
<p>Strings and objects cannot be safely compared.</p>

<p id="demo"></p>

<script>
let x = "John";        // x is a string
let y = new String("John");  // y is an object
document.getElementById("demo").innerHTML = (x===y);
</script>

</body>
</html>

.ﺪﯿﻨﮐ ﻪﺟﻮﺗ (x===y)(x==y) ﻦﯿﺑ ﺕﻭﺎﻔﺗ ﻪﺑ

(x == y) ؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩ

let x = new String("John");
let y = new String("John");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Never Create Strings as Objects</h2>
<p>JavaScript objects cannot be compared.</p>

<p id="demo"></p>

<script>
let x = new String("John");  // x is an object
let y = new String("John");  // y is an object
document.getElementById("demo").innerHTML = (x==y);
</script>

</body>
</html>

(x === y) ؟ﺖﺳﺭﺩﺎﻧ ﺎﯾ ﺖﺳﺍ ﺖﺳﺭﺩ

let x = new String("John");
let y = new String("John");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Never Create Strings as Objects</h2>
<p>JavaScript objects cannot be compared.</p>

<p id="demo"></p>

<script>
let x = new String("John");  // x is an object
let y = new String("John");  // y is an object
document.getElementById("demo").innerHTML = (x===y);
</script>

</body>
</html>

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ falseﻪﺸﯿﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﻭﺩ ﻪﺴﯾﺎﻘﻣ

ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ

:ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

.ﺪﯿﻨﮐ ﻞﻣﺎﮐ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﻊﺟﺮﻣ

.ﺖﺳﺍ ﻪﺘﺷﺭ ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024