JavaScript basic Syntax &4

Source: Internet
Author: User

1: Process Control
if: else; the conditional statement satisfies the execution if inside; does not satisfy the execution else;
If.. ElseIf. Else The layer lookup does not meet the execution else;
for; loop
for; loop object's key;
While/do. While Executes when the condition is always satisfied; Do...while first execution and then judgment at least once;
Switch: Case: Default, Swith write condition to execute, neither satisfies execution of default;
Try: Catch: Finally The code executed in the try, which may have an exception. Once an exception is found, jump to catch execution immediately. Otherwise, the contents of the catch are not executed; finally will be executed;
Throw; throw create custom error; The
With statement can be conveniently used to refer to an existing property in a particular object, but cannot be used to add properties to an object. To create a new property for an object, you must explicitly refer to the object; For example: var people = {' name ': ' Itdsn ', ' age ':--' professional ': ' Webdeveloper '}
with (people) {var str = "Name:" + Nam E + "<br>"; str + = "Age:" + ages + "<br>"; str + = "Occupation:" + professional;document.write (str);}
2: Apply
Slideshow to poll for playback: here starting from 0;
Implementation principle:
Function () {
var max = Math.max.apply (Math, arguments);
Event Occurrence = index + +;
the location to which = (max + index% max)% Max;
}
implements Math.pow ();

function    Pow (n1, n2) {  var y = N1;      for (var i = 1; i < n2; i++= n1*y; }  return  N1;}

lowercase letters to uppercase; implement toLowerCase;

function  toLowerCase (str) {  var reg =/[a-z]/;  for (var i = 0; i < str.length; i++) {  if= str.replace (str[i],string    . fromCharCode (Str[i].charcodeat () +32)); }}  return  str;}
toLowerCase (' Aaaaaa123&&**az ');


Haha, after writing I found that I am good 2;
Can actually directly:

function toLowerCase (str) {  returnfunction(w) {return String.fromCharCode (W.charcodeat ( ) (+32)});}

Determine if lowercase letters/uppercase letters/numbers and count them;

functionStatistical (str) {varUpper = 0, lower = 0, numbers = 0;  for(vari = 0; i < str.length; i++) {if(Str[i].charcodeat () >= 97&& str[i].charcodeat () <= 122) {Lower++}Else if(Str[i].charcodeat () >= && str[i].charcodeat () <= 90) {Upper++; }Else{numbers++; }}return[Upper, lower, numbers];}

Converts the \ t in the string to two spaces;

function Transfrom (str) {  return str.replace (/\\t/g, ' &nbsp;&nbsp; ') );}

Converts a numeric string into a number;

function Transnumber (str) {  return + str.replace (/\d+/g, ');}

Finds characters that appear only once in a string;

function    once (str) {  var arr = [];  for (var i = 0; i < str.length; i++) {  if(Str.lastindexof (str[i]) = = = = S      Tr.indexof (Str[i]) {Arr.push (str[i]); }}  return  arr;}

JavaScript basic Syntax &4

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.