JavaScript notes (Basic)

Source: Internet
Author: User
Tags string methods

1.
------------------------------------------------------------------------------------------
JavaScript can "display" data in different ways:

Writing into an alert box, using Window.alert ().
Writing into the HTML output using document.write ().
Writing into an HTML element, using InnerHTML.
Writing into the browser console, using Console.log ().

Using document.write () after a HTML document is fully loaded, would delete all existing html:the document.write () method s Hould is used only for testing.

The following is not the case:
<! DOCTYPE html>
<body>

<p>my First paragraph.</p>

<script>
Window.alert (5 + 6);
</script>

</body>

------------------------------------------------------------------------------------------
==equal to
===equal Value and Equal type
!=not equal
!==not equal value or not equal type

var x = new String ("John");
var y = new String ("John");
(x = = y) is false because X and Y are different objects
(x = = x) is true because both is the same object
------------------------------------------------------------------------------------------
Typeofreturns the type of a variable
Instanceofreturns true if an object is a instance of an object type

-----------------------------------------------------------------------------------------

var cars = ["Saab", "Volvo", "BMW"]; Array
var x = {firstName: "John", LastName: "Doe"}; Object

----------------------------------------------------------------------------------------
JavaScript Evaluates expressions from left to right. Different sequences can produce Different results:
var x = + 4 + "Volvo";
Result:20volvo

----------------------------------------------------------------------------------------
Array is an object too
typeof [1,2,3,4]//Returns Object
typeof {name: ' John ', age:34}//Returns object
----------------------------------------------------------------------------------------
var person; Value is undefined, type is undefined
person = undefined; Value is undefined, type is undefined
var person = null; Value is null, but type was still an object
NULL = = undefined//False
NULL = = undefined//True
-------------------------------------------------------------------------------------------
Calling functions without parentheses is the printing function
function Tocelsius () {
return (5/9);
}
document.getElementById ("Demo"). InnerHTML = tocelsius;//This is the way to print this function instead of calling
------------------------------------------------------------------------------------------

JS is cheap, there is no class can have the object ...

<script>
var person = {firstName: "John", LastName: "Doe", Age:50, Eyecolor: "Blue"};
document.getElementById ("Demo"). InnerHTML =
Person.firstname + "is" + Person.age + "years-old";
</script>
------------------------------------------------------------------------------------------

You can access the object properties in the ways:

Objectname.propertyname
Or
objectname["PropertyName"]
-----------------------------------------------------------------------------------------
Do not Declare Strings, Numbers, and Booleans as objects!
When a JavaScript variable are declared with the keyword "new", the variable are created as an object:
Don't do this.
var x = new String (); Declares x as a String object
var y = new number (); Declares y as a number object
var z = new Boolean (); Declares Z as a Boolean object
But you can use it directly as an object.
var txt = "abcdefghijklmnopqrstuvwxyz";
var sln = txt.length;
-------------------------------------------------------------------------------------------
If you assign a value to a variable that have not been declared, it would automatically become a GLOBAL variable.
Code here can use Carname
function MyFunction () {
Carname = "Volvo";

Code here can use Carname

}
--------------------------------------------------------------------------------------------
Event:

Eventdescription
Onchangean HTML element has been changed
Onclickthe user clicks an HTML element
Onmouseoverthe user moves the mouse over an HTML element
Onmouseoutthe user moves the mouse away from an HTML element
Onkeydownthe user pushes a keyboard key
Onloadthe Browser has finished loading the page
---------------------------------------------------------------------------------------------
String:

String Properties
Constructorreturns the function that created the String object ' s prototype
Lengthreturns the length of a string
Prototypeallows-to-add properties and methods to an object

String Methods
CharAt () Returns the character at the specified index (position)
charCodeAt () Returns the Unicode of the character at the specified index
Concat () Joins or more strings, and returns a copy of the joined strings
fromCharCode () converts Unicode values to characters
IndexOf () Returns the position of the first found occurrence of a specified value in a string
LastIndexOf () Returns the position of the last found occurrence of a specified value in a string
Localecompare () compares the current locale of strings
Match () searches a string for a match against a regular expression, and returns the matches
Replace () searches a string for a value and returns a new string with the value replaced
Search () Searches a string for a value and returns the position of the match
Slice () Extracts a part of a string and returns a new string
Split () splits a string to an array of substrings
SUBSTR () Extracts a part of a string from a start position through a number of characters
SUBSTRING () Extracts a part of a string between-specified positions
toLocaleLowerCase () Converts a string to lowercase letters, according to the host's locale
toLocaleUpperCase () Converts a string to uppercase letters, according to the host's locale
toLowerCase () Converts a string to lowercase letters
ToString () Returns The value of a String object
toUpperCase () Converts a string to uppercase letters
Trim () removes whitespace from both ends of a string
ValueOf () Returns The primitive value of a String object
-----------------------------------------------------------------------------------------------
Digital:


Propertydescription
Max_valuereturns the largest number possible in JavaScript
Min_valuereturns the smallest number possible in JavaScript
Negative_infinityrepresents negative infinity (returned on overflow)
Nanrepresents a "not-a-number" value
Positive_infinityrepresents Infinity (returned on overflow)
----------------------------------------------------------------------------------------------

JavaScript notes (Basic)

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.