TAILIEUCHUNG - Học JavaScript qua ví dụ part 13

Số lượng, String, hoặc Boolean? Chuyển đổi kiểu dữ liệu Theo định nghĩa trước đó, JavaScript là một ngôn ngữ lỏng lẻo nhập, mà thực sự có nghĩa là bạn không cần phải được quan tâm về những loại dữ liệu được lưu trữ trong một | 112 Chapter 5 Operators EXPLANATION continued 2 When the bitwise OR operator is applied to 1111 1001 the result is binary 1111 or decimal 15. 3 When the bitwise A Exclusive OR is applied to 1111 a 1001 the result is binary 0110 or decimal 6. 4 9 2 yields 36 because 1001 shifted two bits to the left becomes 100100 which is decimal 36. 5 9 2 yields 2 because 1001 shifted two bits to the right becomes 10 which is decimal 2. 6 9 2 yields 3 because the sign is preserved. 7 15 2 yields 3 because 1111 shifted two bits to the right becomes 0011 which is decimal 3. For nonnegative numbers zero-fill right shift and sign-propagating right shift yield the same result. See Figure . Testing Bitwise Operators 15 9 yields 9 15 9 yields 15 15 A 9 yields 6 9 2 yields 36 9 2 yields 2 -9 2 yields -3 15 2 yields 3 Figure Output from Example . Number String or Boolean Data Type Conversion As defined earlier JavaScript is a loosely typed language which really means that you don t have to be concerned about what kind of data is stored in a variable. You can assign a number to x on one line and on the next line assign a string to x you can compare numbers and strings strings and Booleans and so on. JavaScript automatically converts values when it assigns values to a variable or evaluates an expression. If data types are mixed . a number is compared with a string a Boolean is compared with a number a string is compared with a Boolean JavaScript must decide how to handle the expression. Most of the time letting JavaScript handle the data works fine but there are times when you want to force a conversion of one type to another. For example if you prompt a user for input the input is set as a string. But suppose you want to perform calculations on the incoming data making it necessary to convert the strings to numbers. When using the operator you want to add two numbers that have been entered as strings not concatenate them so you will then need to convert the data from .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.