JavaScript Assignment
عملگرهای تخصیص
عملگرهای تخصیص، مقداری را به متغیرهای جاوا اسکریپت نسبت میدهند.
عملگر | مثال | مشابه است با |
---|---|---|
= | x = y | x = y |
=+ | x += y | x = x + y |
=- | x -= y | x = x - y |
=* | x *= y | x = x * y |
=/ | x /= y | x = x / y |
=% | x %= y | x = x % y |
=** | x **= y | x = x ** y |
عملگر =
<!DOCTYPE HTML>
<html>
<body>
<h2> The = Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
عملگر =+
<!DOCTYPE HTML>
<html>
<body>
<h2> The += Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
x += 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
عملگر =-
<!DOCTYPE HTML>
<html>
<body>
<h2> The -= Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
x -= 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
عملگر =*
<!DOCTYPE HTML>
<html>
<body>
<h2> The *= Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
x *= 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
عملگر =/
<!DOCTYPE HTML>
<html>
<body>
<h2> The /= Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
x /= 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
عملگر =%
<!DOCTYPE HTML>
<html>
<body>
<h2> The %= Operator </h2>
<p id = "demo"> </p>
<script>
var x = 10;
x %= 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>