javascript problems for beginners

Learn about javascript problems for beginners, we have the largest and most updated javascript problems for beginners information on alibabacloud.com

Problems with variable objects in JavaScript

obj1 = {o1[drt]:333};var obj2 = {o2[0]:333}; The first three lines of code are several different ways of declaring a variable, that is, a normal variable, an object, an array, and the last three rows that call each of these 3 variables and insert the object. Here's the problem:1. Why Obj1 and OBJ2 statements when the direct error?2. obj did not complain, but why loop his properties when the first attribute is directly called "O" instead of the value "left" of the variable O? If I wan

Creating JavaScript standard objects--frequently encountered problems in interview

Creating objects with constructors, using prototypes to add methods to functions function Person (name,age,sex) { This. Name=name; This. Age=age; This. Sex=sex; } Person.prototype.play=function () { Return "I am:" +this. Name+ ", Name:" +this. Age+ ", Age:" +this. Sex+ ""; } Person.prototype.fav=function (food) { Return "I love to Eat" +food+ ""; } var per=new person (' Xiao ', ' n ', ' NV '); Alert (Per.play ()); Alert (per.fav ("Apple")); Creating

Value passing and reference passing problems for Javascript Date types

Creates a new variable of type date D1.The post-run page will pop up:Fri Sep 16:40:50 gmt+0800Create a new variable d2, assign the value of D1 to D2, set the D2 year to 2013,The post-run page will pop up:Thu Sep 16:40:50 gmt+0800Thu Sep 16:40:50 gmt+0800Even if the D2 is declared as a date type, the result is still the same.indicates that this direct assignment of the date type becomes a reference value, D1, D2 two variables to the same date object. It is important to use the "=" symbol to assig

JavaScript problems with the For loop removing the contents of an array element _javascript tips

The problem that occurs yesterday when you use a For loop to go to the weight of an array, First, the previous and all subsequent elements are compared with the double for loop, and if equal is deleted. However, problems can occur if there are more than three consecutive equal elements in the array. var arr = [1,1,1,2,2]; For (Var i=0. i Output: This is because when an array deletes an element, the length of the array is reduced by 1

Analysis of the problems in JavaScript-type chain in the _javascript techniques

We know that using a prototype chain to implement inheritance is a goodway: Look at an example of a prototype chain inheritance. function A () { this.abc =; } A.PROTOTYPE.GETABC = function () {return this.abc; }; Function B () { } B.prototype = new A ();//b completes inheritance through an instance of a, forming a prototype chain (the prototype of B is an instance of a) var b = new B (); The relationship is as follows: B (instance)->b.prototype = new A ()-> A.prototype->object.prot

innerHTML problems in JavaScript

When getting document.getElementById (), use innerHTML to get the tag to get the content, note:1. To allow the content to be loaded before it can be used, otherwise get empty, using: Window.onload = ....2. Or put the script behind the contentDOCTYPE HTML>HTMLLang= "en">Head> MetaCharSet= "UTF-8"> title>title> Script>window.onload= function() { varMyID=document.getElementById ("Con"); //alert ("test");document.write ("contents of original HTML:" +myid.innerhtml+ ""); Myid.inne

Problems with JavaScript floating point arithmetic (multiplication)

Problems with JavaScript floating point arithmetic (multiplication)

Easily fix JavaScript date formatting problems

1Date.prototype.format =function(f) {2 varD = This3f = F | | "Yyyy-mm-dd Hh:mm:ss"4 returnF.replace (/[ymdhms]+/g,function(item) {5 Switch(item) {6 Case"YYYY":7 returnd.getfullyear ()8 Break9 Case"MM":Ten return+d.getmonth () + 1 One Break A Case"DD": - return+d.getdate ()

Computational problems in JavaScript

stored in the variable is also copied into the space allocated for the new variable.At this point in the variable is the address of the object in the heap memory, so, unlike the simple assignment, the copy of this value is actually a pointer, and this pointer points to an object stored in the heap memory. Then after the assignment operation,Two variables all hold the same object address, the two variables point to the same object. Therefore, changing any one of these variables will affect each

Problems with JavaScript prototype inheritance

];} Worker.prototype.showJob=function() {Console.log ( This. Job);} Worker.prototype.walk=function(){//The way the prototype chain is used overrides the method in the parent classConsole.log ("Go Backwards");} Worker.prototype.language= "中文版";varp1=NewPerson ("blue", "male") P1.showname ();//BlueP1.showsex ();//maleP1.walk ();//go ahead.Console.log (P1.language)//ChineseConsole.log (PERSON.PROTOTYPE.SHOWJOB)//undefined If you use worker.prototype=person.prototype then there is a subclass Showjob

Variable re-assignment and reference re-assignment problems in JavaScript

This is a common problem in javascript:var A=3;var b=a;a=5; The result was 5;; The result is 3; and the situation in the following code has changed: var A=1,b=2,c=3;var array=[a,b,c];a=5;; The result of //was 1, and there was no change; var A=1,b=2,c=3;var Array=[a,b,c]; array[0]=5;; The result is that 1,a has not changed in the following code the situation is different: var A=1,b=2,c=3;var array=[a,b,c]; Array2=array; array[0]=5;; The result is 5;var A=1,b=2,c=3;var Array=[a,b,c];var Array2=ar

Problems of javascript--pre-parsing in IE

123456 + A the + -Problems of javascript--pre-parsing in IE

Scope problems of variables in JavaScript constructors

The constructor can be used with new, representing the creation of an object, or as a normal function call because it is also a function.function person (name) {this.name=name;} Person (n); alert (window.name);//12You can see that this represents a global window object when the constructor is called as a normal function. Obviously it is not a good practice to call a constructor function as a normal function, and there is no reason to do so. In practice, such strange usages should be eliminated i

Deep analysis of JavaScript cross-domain problems _javascript skills

What is a cross domain? Suppose a.com/get.html need to get b.com/ Data.html in the data, and here a.com and B.Com is not the same server, this is Cross-domain Cross-domain will involve JavaScript homology strategy, simply to protect the site security, not by the alien (not homologous) Server JS Modify this site content.Refer to a table to see what conditions are causing the cross-cause: But sometimes we do need to do this, so what are the ways we

Total Pages: 9 1 .... 5 6 7 8 9 Go to: Go

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.