google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Rèn luyện các toán tử và biểu thức JavaScript Bài viết JavaScript này sẽ cung cấp cho bạn đầy đủ tất cả chỉ dẫn và ví dụ về toán tử và biểu thức trong ngôn ngữ lập trình JavaScript: toán tử so sánh, typeof, void, toán tử dấu phẩy, toán tử điều kiện, toán tử luận lý, toán tử bit, toán tử số học, toán tử gán.


Miễn phí web hosting 1 năm đầu tại iPage



Nếu bạn vẫn còn đang tìm kiếm một nhà cung cấp hosting đáng tin cậy, tại sao không dành chút thời gian để thử với iPage, chỉ với không quá 40.000 VNĐ/tháng, nhưng bạn sẽ được khuyến mãi kèm với quà tặng trị giá trên 10.000.0000 VNĐ nếu thanh toán cho 24 tháng ~ 900.000 VNĐ?

Có trên 1 triệu khách hàng hiện tại của iPage đã & đang hài lòng với dịch vụ, tuyệt đối chắc chắn bạn cũng sẽ hài lòng giống họ! Quan trọng hơn, khi đăng ký sử dụng web hosting tại iPage thông qua sự giới thiệu của chúng tôi, bạn sẽ được hoàn trả lại toàn bộ số tiền bạn đã sử dụng để mua web hosting tại iPage. Wow, thật tuyệt vời! Bạn không phải tốn bất kì chi phí nào mà vẫn có thể sử dụng miễn phí web hosting chất lượng cao tại iPage trong 12 tháng đầu tiên. Chỉ cần nói chúng tôi biết tài khoản của bạn sau khi đăng ký.

Nếu muốn tìm hiểu thêm về ưu / nhược điểm của iPage, bạn hãy đọc đánh giá của ChọnHostViệt.com nhé!
Thử iPage miễn phí cho năm đầu tiên NGAY

JavaScript Assignment Operators

JavaScript Assignment operators are used to assign values to JavaScript variables. In many cases or instances JavaScript Assignment Operator is used to set a variable to a literal value, for example:

var studentName = "Max"; //studentName set to Max
var aNumber = 1982; //aNumber set to 1982
var isNumber = true; //isNumber set to true

Lets consider x=10 and y=5, the table below explains the advanced use of assignment operators:

Table 1 -JavaScript Assignment Operators
Operator Example Equivalent Result
= x=y   x=5
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
%= x%=y x=x%y x=0
<<= x <<= y x = x << y x=320
>>= x >>= y x = x >> y x=0
>>>= x >>>= y x = x >>> y x=0
&= x &= y x = x & y x=0
|= x |= y x = x | y x=15
^= x ^= y x = x ^ y x=15

JavaScript Arithmetic Operators

Arithmetic operators are used to perform all the basic arithmetic operations between operands (inputs) i.e. variables and/or values.

Table 2 - JavaScript Arithmetic Operators
Operator Meaning Example Result
+ Addition x=4+2 x=6
- Subtraction x=4-2 x=2
* Multiplication x=4*2x x=8
/ Division x=5/2 x=2.5
% Modulus (remainder) x=5%2 x=1
++ Increment x=++5 x=6
- Decrement x=-5 x=4

JavaScript Comparison Operators

JavaScript Comparison operators are used in logical statements to determine equality or difference between variables or values. JavaScript comparison Operators evaluates to a Boolean value indicating whether its comparison is true or false. Most of JavaScript's comparison operators should be familiar to elementary mathematics Comparison Operators.

Table 3 - JavaScript Comparison Operators
Operator Meaning Example Result
< Less than 5 < 8 true
<= Less than or equal to 8 <= 5 false
> Greater than 8 > 3 true
>= Greater than or equal to 5 >= 5 true
!= Not equal to 8 != 5 true
== Equal to 9 == 5 false
=== Equal to (identical) 5 === '5′ false
!== Not equal to 5 !== '5′ true

JavaScript Bitwise Shift Operators

JavaScript Bitwise Shift Operators are used to move (shift) bits around rather than set them. Bitwise shift operators take two operands. The first is the number to be shifted, and the second specifies the number of bit positions by which all the bits in the first operand are to be shifted. The direction of the shift operation is controlled by the operator used, << for left shift and >> for right shift.

Table 4 - JavaScript Bitwise Shift Operators
Operator Description Example Intermediate Step Result
<< Left shift 4<<3 00000100 shifted to the left three spots and filled with zeros results in 00100000. 32
>> Right shift with sign extend -9>>2 11110111 shifted to the right two spots and left-filled with the sign bit results in 11111101. -3
>>> Right shift with zero fill 32>>>3 00100000 shifted to the right three spots and left-filled with 0 results in 00000100. 4

JavaScript Logical Operators

JavaScript Logical operators are used to determine the logic between variables or values. The logical operators && (AND), || (OR), and ! (NOT) are useful to combine such values together in order to implement more complicated logic. The most common use of the logical operators is to control the flow of script execution using conditional statement.

Table 5 - JavaScript Logical Operators
&& true if both operands evaluate true; otherwise returns false. var x=true, y=false; alert(x && y); // displays false
|| Returns true if either operand is true. If both are false, returns false. var x=true, y=false; alert(x || y); // displays true
! If its single operand is true, returns false; otherwise returns true. var x=true; alert(!x); // displays false

JavaScript Conditional Operator

JavaScript Conditional Operator evaluate eventually a condition to true or false. If expression evaluates true, if-true-statement is evaluated. Otherwise, if-false-statement is executed.

The basic syntax for JavaScript Conditional Operator:

(expression) ? if-true-statement : if-false-statement;
var x=7;
(x >> 5) ? alert("x is greater than 5") : alert("x is less than 5");

JavaScript Comma Operator

The comma operator (,) allows multiple expressions to be strung together and treated as one expression. Expressions strung together with commas evaluate to the value of the right-most expression. JavaScript Comma Operator mostly use with for condition.

var a,b,c,d;
for(i=0; i<=10; i++)
{
//Some JavaScript Statements
}

JavaScript void Operator

The void operator specifies an expression to be evaluated without returning a value.

var a=0;
a = void (d=56);
alert(a); // the value of 'a' will alert as 'undefined'

JavaScript typeof Operator

The typeof operator returns a string indicating the data type of its operand.

var a=3
var name = "I Love JavaScript";
alert(typeof a);       // alert 'number'
alert(typeof name);    // alert 'string'

Table 6 - JavaScript typeof Operator Return Values
Type String Returned by typeof
Boolean "boolean"
Number "number"
String "string"
Object "object"
Function "function"
Undefined "undefined"
Null "object"
iPhoneKer.com
Save up to 630$ when buy new iPhone 15

GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project

https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools

chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language

Dall-E-OpenAI.com
Generate creative images automatically with AI

AIVideo-App.com
Render creative video automatically with AI

JavaScript theo ngày


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web