ComputersProgramming

JavaScript: application examples

If you do not immediately immerse yourself in the concise syntax and functionality of JavaScript semantics, simple code examples will help you quickly learn how to improve the dynamics and efficiency of your pages.

JS is the programming language inside the browser. JavaScript has a solid experience for working with page elements, original solutions in the field of object-oriented programming, "knows how" to communicate with the server, because numerous JavaScript examples of code are not immediately available for understanding and application.

General through private: a simple start

Programming inside the browser is still relatively young, but quickly accumulated a quality and original experience. Syntax and semantics JavaScript received from titled "ancestors", and in terms of functionality and practicality of the syntax - since the pre-Internet programming languages, primarily C / C ++, Pascal.

Looking through the JavaScript examples, one should not strive to immediately understand the logic of the authors thinking and the functionality of the algorithms - this is a little-promising occupation, it's better to emphasize your own private practice.

Simply start by connecting the onload handler in the body tag and write the traditional "Hello" in the modern style "I`m ready".

These JavaScript examples show:

  • The onload event that occurs after loading the page is assigned a handler - the GoPage () function;
  • The page is loaded, and the GoPage () function gets control;
  • Call the internal function of the alert language, which displays a message in the browser "I'm ready";
  • The browser is waiting for the visitor's response.

The comments contain descriptions of the actions that should normally be taken after loading the page and starting the timer.

Very handy: JS is very closely related to the elements of the page. So, the call to document.getElementById gives a reference to the div with the identifier "scTimer". Using the dTimer.innerHTML = "any valid HTML code" design , you can dynamically change the contents of this div.

You should pay special attention to the undesirability of errors in the scripting body of JavaScript. Examples of this have negative consequences. The above code says alert ('I'm ready'), and it will not work. To designate strings, any kind of apostrophes is allowed: both single and double, and within a pair of one type one can be used, the other as a symbol.

In this case, it should be indicated: either alert ("I'm ready"), alert ('I`m ready'), alert ('I \' m ready '), or other combinations.

About errors in JS-code

Initially there was a browser, on the initiative of the visitor, he uploaded the page of the site, built a DOM tree and enabled JavaScript to act: gave him the opportunity to analyze the loaded page, initialize its elements, connect event handlers and establish contact with the server.

Analyzing JavaScript (examples), you need to pay attention to debugging the code. This procedure mostly falls on the developer. The browser in which the work is done can offer some debugging tools, but practice shows that strict observance of the syntax of the language, simplicity and correctness of the algorithm have a much greater effect for achieving the working result.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.