JavaScript notes and summaries (2-3) JavaScript operators, control structures, and object operations

Source: Internet
Author: User

" Join operator +"

<script>Console.log (1+2+ ' a ' +3+4);</script> 

Output:

3a34

The logical operator returns the first value that can determine the result of an expression

Example ①

<script>varfalse; var b = Ten; var true ; var d = A | | B | | C;console.log (d); Console.log (typeof(d)); </script>

Output:

10

Number

Example ②

<script>var a = True; var B = False; var C = a && b;console.log (c); Console.log (typeof(c)); < ;/script>   

Output:

False

Boolean

Example ③ (&& priority above | | )

<script>vartrue; var b = Ten; var false ; var d = A | | b && C;console.log (d); Console.log (typeof(d)); </script>

Output:

True

Boolean

Often used in some frameworks | | To do browser compatibility, form: WINDOW.A = WINDOW.A | | window.b

" iterating over an array "

<script>var arr = [' Hello ', ' world ',];  for (var i=0; i<arr.length; i++) {    console.log (arr[i]);} </script>

Output:

Hello

World

2015

" Traverse Object "

<script>var obj = {A: ' Hello ', B: ' World ', c:2015};  for (var in obj) {    Console.log (key+ ":" +Obj[key]);} </script>

Output:

A:hello

B:world

c:2015

" Object Actions "

When calling properties with native types such as numbers, strings, JS will instantly wrap these native types into objects

Example ①

<script>var str = "HelloWorld"; Console.log (str.length); </script>

Output 10

Example ②

<script>var str = "HelloWorld"; Console.log (str.substr (2,3)); </script>

Output: Llo

Example ③

<script>var arr = [' Arsenal ', ' Chelsea ', ' Manchester City ', ' Liverpool '];console.log (arr.join (')')var str = "Php,java,python"; Console.log (Str.split (', ')); </script>

Output:

Arsenal, Chelsea, Manchester City, Liverpool

["PHP", "Java", "Python"]

JavaScript notes and summaries (2-3) JavaScript operators, control structures, and object operations

Related Article

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.