Preliminary JavaScript Learning

Source: Internet
Author: User
Tags float double

After reading the video tutorial "21 days learning JavaScript", I feel that I am familiar with the syntax, similar to C ++, similar to C #, and similar to Java! Sorry, these languages have similar syntaxes, such as data types and object methods (or functions). Since I am a cainiao, I cannot tell you exactly what it is ).

In JavaScript, data types are classified into integer and floating-point types. Here, the floating-point type does not have the same single-precision or double-precision expression. The declaration of all variables only needs to use VaR (which is easy, do not record int long float double ......) What type of value you pay for it, and what type it is. Also, do not distinguish between characters and strings. In the past, sometimes, when using C #, it seems that "… Cannot be used as a string ". It's easy to remember, haha ............

The string type is similar to the string type in other languages. You can perform operations on the string, such as string truncation substring. The following is an example of a javascript string operation:

 

Javascript string operations

  1   <  Title  >  Example 2 -  10  <  /  Title>  
2   < Script Language = " Javascript " >
3   <! --
4 // Poetry content
5   VaR Comment = " Quiet night Li Bai bed in front of the bright moonlight, suspected to be on the ground frost. Look up at the moon and look down at your hometown. " ;
6 VaR Partial = Comment. substring ( 0 , 3 ); // Retrieve title
7   Partial = Partial. Bold (); // Bold title
8 Document. Write ( " <P align = \ " Center \ " > " ); // Output the HTML Tag "<p>" and set center alignment.
9 Document. Write (partial ); // Output title
10 Partial = Comment. Slice ( 3 , 5 ); // Extract author
11 Document. Write ( " <Br/> " ); // Output line feed label <br/>
12 Document. Write (partial ); // Output author
13 Partial = Comment. Slice ( 5 , 17 ); // Extract the first poem
14 Partial = Partial. fontcolor ( " Gray " ); // Set the color to Gray)
15 Document. Write ( " <Br/> " ); // Output line feed label
16 Document. Write (partial ); // Output verse
17 Partial = Comment. Slice ( 17 , 29 ); // Extract the second poem
18 Partial = Partial. fontcolor ( " Gray " ); // Set the color to Gray)
19 Document. Write ( " <Br/> " ); // Output line feed label
20 Document. Write (partial ); // Output verse
21 Document. Write ( " </P> " ); // Output the end tag of the HTML Tag "<p>"
22 -->
23 < / SCRIPT>

 

Composite data types in Javascript

Arrays and functions are also available in JavaScript. The definition of arrays is similar to that of C # And C ++.

The following is an example of an array:

Looking at the sudden appearance, there is an interesting operator in Javascript, "=", which is used to determine whether data is equal, the data must be equal not only in values but also in data types. Oh, this is a bit dizzy.

 

  1   <  Script  >  
2 <! --
3 VaR X = 10 ;
4 VaR Y = Null ;
5 If (X = Null )
6 {
7 Document. Write ( " The value of X is null. <br/> " ); // Output prompt
8 }
9 If ( Null = Y)
10 {
11 Document. Write ( " The value of Y is null. <br/> " ) // Output prompt
12 }
13 -->
14 < / SCRIPT>

 

Conversion of values in Javascript

There are also conversions of numeric types in Javascript, including display conversions and implicit conversions, which are basically similar to those of C ++. As this is a note, I will not write it.
And almost all webProgramming LanguageSimilarly, "=" and "=" are different. One is to determine whether the value is equal, and the other is to determine whether the value and type are completely equal. I want to take notes separately later. It's already quite long. For me, I have never written such a long thing ...... There is no habit of writing notes separately.

It's sent here today ...... Continue later.

Good good study, day up!

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.