By: aathishankaran in Javascript Tutorials on 2007年03月21日 [フレーム]
JavaScript execution begins after the HTML document loads into the browser, but before the users can interact with the document. The browser reads in all JavaScript statements, as it does HTML statements, and then begins interpreting the JavaScript code.
If your JavaScript scripts are stored in a separate file, they are also evaluated when the page loads and before any script actions take place.
All JavaScript statements that are contained within a function block are interpreted, and execution does not occur until the function is called from a JavaScript event. JavaScript statements that are not within a function block are executed after the document loads into the browser. The execution results of the latter will be apparent to the users when they first view the page. The second process which JavaScript executes statements is though function calls. Any statement contained within a function will not be executed until a JavaScript event calls the function. .
As in any other programming language, JavaScript statements can be implemented using various methodologies. A function has to be defined in the <HEAD>section and then calling these functions within the HTML body is the best w to take advantage of the object-based JavaScript language. Java script is simple to understand. Although HTML statements are not case-sensitive, JavaScript statements are.
When beginning to write your code, keep the following items in mind:
You can use JavaScript tags in either the body or the head of a document. Placing the <SCRIPT>in the head rather than the body ensures that all statements will be evaluated (and executed, if necessary) before the user interacts with the document. The hazards of putting script statements in the body of the document are varied. Depending on the specific tags and the order of the document, you can never be positive that the user will not interact with the script in the wrong manner or react to the page before the script has fully loaded or executed. If any of these occur, the effect that you want for your page might not be seen. (After all your effort, who wants that?) The practice of defining your JavaScript functions and then calling them from the body will ensure that all the functions are evaluated before the user can begin interaction with the page.
Example:
<script>
console.log("Hello World");
</script>
As you probably realized, JavaScript scripts are as simple to load as HTML documents. You do not have to explicitly execute any code to run your scripts, because you place your code in the HTML document or call it explicitly in the first script line, your script will run when the page loads. Remember that not all the code will necessarily execute immediately upon loading. Code that is enclosed in a function call is only evaluated when the page loads but does not execute until the function is explicitly called from a JavaScript event. Code that is not enclosed in a function call runs after the page finishes loading but before the user has a chance to interact with the page.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Javascript )
Dynamically modify the option set in Dynamics 365 forms
promise and .then() in JavaScript
reduce() and filter() in JavaScript
History and evolution of Javascript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Show how many characters remaining in a html text box using javascript
Latest Articles (in Javascript)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate