INTRODUCTION TO JAVASCRIPT
Javascript is a scripting language, single thread, conforming to the ECMAScript specification that can operate both client-side and server-side and is compiled and interpreted.
- A scripting language is a language that needs to be executed within a pre-existing entity in order to operate. In the case of javascript, the entity is the web browser.
- Single Thread. Imagine a post office with a single operator who has to serve n customers. What the operator can do however fast is to serve one person at a time. People in the queue must wait for the user currently served to leave the queue to make room for the next person. As an analogy let’s say that post office is single-threaded. Every web browser has within it a component called a javascript engine whose job is to execute javascript code. Like the post office analogy, the engine takes the instructions in our program one by one and converts them into machine code, that is, binary code that can be executed on our devices.
Single Thread means that it can only do one thing at a time.
ECMASCRIPT
- The javascript engine integrates, in the new versions of the respective browsers, the features outlined in the ECMAScript specification. This allows developers to write code with the new features because they will be fully supported by newer browsers, but not by older generation browsers. ECMAScript is a standards-setting organization. Javascript conforms to the ECMAScript specification.
- Javascript started as a client-side programming language, since 2009 it is also a server-side language thanks to Node js. The idea behind Node js was to take the javascript engine, which is software, and put it into servers so that it can interact with databases and file systems.
- Let us make a premise, the devices are capable of understanding long sequences of zeros and ones. Such language is called machine code. High-level languages such as javascript, PHP, C# are understandable to us humans but not by the devices we use. Code produced by one of these languages, either those called interpreted or compiled must go through a series of transformations to be understood by our device. For compiled languages compilation must be performed before executing the code, in interpreted languages the code is evaluated by an interpreter, for example in the case of javascript we can write our code and insert it into the body of an HTML page. We open the page through a browser and the code will be processed. The javascript engine also integrates a JIT compiler internally, so, it is not just interpreted, interpreter and compiler work symbiotically to optimize the code.
WHAT IS JAVASCRIPT
JavaScript is an object-oriented and event-oriented programming language. Commonly used in client-side web programming (later extended to server-side thanks to Node js) for creating websites and web applications with dynamic interactive effects, via script functions, invoked by events triggered in turn by the user on the web page in use (mouse, keyboard, page loading etc.). Originally developed by Brendan Eich of Netscape Communications under the name Mochan and later LiveScript, it was later renamed “JavaScript” and was formalized with a syntax closer to that of Sun Microsystems’ Java language (which was acquired by Oracle in 2010).
DESCRIPTION
Script functions, thus used in presentation logic, can be appropriately placed in HTML files, in JSP pages or in separate files with the .js extension then called in the business logic. Lately its field of use has been extended to so-called Hybrid Apps, with which it is possible to create apps for multiple operating systems using a single source code based precisely on JavaScript, HTML and CSS.
STRUCTURAL ASPECTS
The main features of JavaScript are:
- The syntax is relatively similar to that of the C, C++ and Java languages.
- It defines features typical of high-level programming languages (control structures, loops, etc.) and allows the use of the object-oriented paradigm.
- It is a weakly typed language.
- It can use Unicode characters.
- Can evaluate regular expressions (introduced in version 1.2; browser support: starting with Netscape Navigator 4 and Internet Explorer 4).
WHAT MAKES JAVASCRIPT UNIQUE?
- Full integration with HTML/CSS.
- Simple operations are performed simply.
- Supported by major browsers and integrated by default.
JAVASCRIPT FUNCTIONS AND EVENTS
In HTML, JavaScript code is inserted between the tags <script> and </script>. Older JavaScript examples may use a type attribute:<script type = “text/javascript”>. The type attribute is not required. JavaScript is the default scripting language in HTML. A JavaScript function is a block of code, which can be executed when “called”. For example, a function can be called when an event occurs, such as when the user presses a button.
. The type attribute is not mandatory. JavaScript is the default scripting language in HTML. A JavaScript function is a block of code, which can be executed when "called upon." For example, a function can be called when an event occurs, such as when the user presses on a button.
JAVASCRIPT CODE IN THE HEAD TAG
CODE IN THE BODY TAG
Placing scripts at the bottom of the element improves display speed, as script interpretation slows down the display.
EXTERNAL JAVASCRIPT
External scripts are practical when the same code is used on many different Web pages. JavaScript files have the extension .js. To use an external script, enter the name of the script file in the src (source) attribute of a <script tag>:
<script src=“myScript.js“></script>
Embedding scripts in external files has some advantages:
- Separate HTML and code
- Makes HTML and JavaScript easier to read and maintain
- Cached JavaScript files can speed up the loading of pages
Leave A Comment