JavaScript data type conversion considerations _javascript Tips

Source: Internet
Author: User

1. Non-variability of strings

After the string is defined, it will occupy the memory space, the Penguin the Memory Space (stack) can not be assigned a value.

2. Short Circuit operation

The && two operator returns the original value (original data type and original data) of the operand that participated in the operation.

At the end of the operation, returns the operand that caused the operation to end.

3. Ternary operator

Code1?   Code2:code3; Different from If-else:

Returns the value of the Code2 or code3----code2,code3 can be replaced with an empty {};

Can't write Break,continue.

4.NaN

NaN! =nan,

Any mathematical operation in which Nan participates, the result is Nan

conditional expression with Nan participation: comparison operator >/>=/</<=/==/=== operation result is False

! ==/! = The result of the operation is true

<script>
  var A;
  Console.log (Boolean (nan>=4));
  Console.log (Boolean (nan<4));
  Console.log (Boolean (nan=4));
  Console.log (Boolean (nan==4));
  Console.log (Boolean (a=4));
  Console.log (NaN);
  Console.log (a);
  if (Nan==nan) {
    a = "Nan==nan";
  }
  var b;
  if (Nan!==nan) {
    b = "Nan!=nan";
  }
  Console.log (A + "\ n" +b);
</script>

5. JS simple data type conversion---special case demo
Data: 0, "", false,null,undefined, "123abc" etc

<! DOCTYPE html>  

This is the entire content of this article to share, I hope you can enjoy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.