What's Javascript?

ZiksthemW

Uzman üye
28 Mar 2020
1,026
113
Oslo
w9u60357jk4ozdho7urq.jpg


Introduction to JavaScript

Let's take a look at what's so special about JavaScript, what you can achieve with it, and what other technologies work well with it.

What is JavaScript?

JavaScript was originally created to "make web pages come alive."

Programs in this language are called scripts. They can be embedded in HTML and executed automatically when the web page is loaded.

Scripts are distributed and executed as plain text. They don't need any special preparation or compilation to run.

This distinguishes JavaScript from another language, Java.

Hint' Alıntı:
Why JavaScript?
When JavaScript was created, it had a different name - "LiveScript". However, the Java language was very popular at the time, and it was decided that positioning JavaScript as Java's little brother would be useful.

Over time, JavaScript has become a completely independent language with its own specification called ECMAScript, and now has nothing to do with Java.

Today JavaScript can run not only in a browser, but also on a server or any other device that has a special program called a JavaScript "engine".

The browser has its own engine, sometimes referred to as the "JavaScript virtual machine".

Different engines have different "codenames". For example:

  • V8 - in Chrome and Opera.
  • SpiderMonkey - in Firefox.
  • ... There are also "Trident" and "Chakra" for different IE versions, "ChakraCore" for Microsoft Edge, "Nitro" and "SquirrelFish" for Safari, etc.

These names are useful to know as they are often used in developer articles. We will use them too. For example, if "X functionality is supported by V8," then "X" is likely to work in Chrome and Opera.

Hint' Alıntı:
How do engines work?
The engines are complex. But the basics are easy to understand.

The engine (built-in if it is a browser) reads ("parses") the script text.
It then converts ("compiles") the script into machine language.
After that, the machine code starts up and runs fast enough.
The engine applies optimizations at every stage. He even looks at the compiled script as it runs, analyzing the data passing through it, and applying optimizations to the machine code, relying on the knowledge gained. As a result, the scripts are very fast.

What can JavaScript do in the browser?

Modern JavaScript is a "safe" programming language. It does not provide low-level memory or cpu access because it was originally built for browsers that do not require it.

JavaScript's capabilities are highly dependent on the environment in which it runs. For example, Node.JS supports functions for reading / writing arbitrary files, making network requests, etc.

Everything related to manipulating web pages, user interaction and web server is available in the browser for JavaScript.

For example, in a browser, JavaScript can:


  • [*] Add new HTML code to the page, modify existing content, modify styles.
    [*] React to user actions, mouse clicks, pointer movements, keystrokes.
    [*] Send network requests to remote servers, download and upload files (AJAX and COMET technologies).
    [*] Receive and set cookies, ask questions to the visitor, show messages.
    [*] Remember data on the client side ("local storage").

What JavaScript can NOT in the browser?

JavaScript capabilities in the browser are limited for the sake of user safety. The aim is to prevent an unscrupulous web page from accessing personal information or damaging user data.

Examples of such restrictions include:


  • [*]JavaScript on a web page cannot read / write arbitrary files on the hard drive, copy them, or run programs. It does not have direct access to OS system functions.

    Modern browsers allow it to work with files, but with limited access, and only provide it if the user performs certain actions, such as "dragging" the file into the browser window or selecting it using the <input> tag.

    There are ways to interact with the camera / microphone and other devices, but these require explicit permission from the user. Thus, a page with JavaScript support cannot invisibly turn on the webcam, watch what is happening and send information to the FSB.
  • Different windows / tabs are not aware of each other. Sometimes one window, using JavaScript, opens another window. Even so, JavaScript from one page does not have access to another if they come from different sites (from a different domain, protocol, or port).

    This is called the Same Origin Policy. To work around this limitation, both pages must agree to this and contain JavaScript code that communicates in a special way.

    This limitation is necessary, again, for the safety of the user. The page https://anysite.com that the user opened should not be able to access another browser tab with the URL https://gmail.com and steal information from there.
  • JavaScript can easily communicate with the server that the current page came from. But its ability to fetch data from other sites / domains is limited. Although this is possible in principle, which requires explicit consent (expressed in HTTP headers) with the remote side. Again, this is a security limitation.



Such restrictions do not apply if JavaScript is used outside the browser, for example, on the server. Modern browsers provide plugins / extensions with which additional permissions can be requested.

What makes JavaScript special?

There are at least three strengths of JavaScript:

LIST' Alıntı:

  • [*] Full integration with HTML / CSS.
    [*] Simple things are easy to do.
    [*] Supported by all major browsers and enabled by default.

JavaScript is the only browser technology that combines all three of these things.

This is what makes JavaScript so special. This is why it is the most common tool for creating interfaces in the browser.

Although, of course, JavaScript allows you to create applications not only in browsers, but also on the server, on mobile devices, etc.

Languages ​​over JavaScript

JavaScript syntax doesn't fit all needs. Different people want different opportunities.

This is natural, because the projects are different and the requirements for them are also different.

So, recently there have been many new languages ​​that are transpiled (converted) to JavaScript before being launched in the browser.

Modern tools make transpilation very fast and transparent, effectively allowing developers to write code in another language, automatically converting it to JavaScript under the hood.

Examples of such languages:


  • [*] CoffeeScript adds syntactic sugar for JavaScript. It introduces a shorter syntax that allows you to write clean and concise code. This is usually what Ruby programmers like.
    [*] TypeScript concentrates on adding "strong typing" to make it easier to develop and maintain large, complex systems. Developed by Microsoft.
    [*] Flow also adds typing, but in a different way. Developed by Facebook.
    [*] Dart stands out because it has its own engine that runs outside the browser (for example, in mobile applications). It was originally proposed by Google as a replacement for JavaScript, but at the moment it needs to be transpiled to run in the same way as for the above languages.
    [*] Brython transpiles Python to JavaScript, allowing you to write pure Python applications without JavaScript.

There are others. But even if we use one of these languages, we need to know JavaScript to really understand what we are doing.

Conclusion

  • [*] JavaScript was originally written only for the browser, but is now used on many other platforms.
    [*] JavaScript today is uniquely positioned as the most widely used browser language with full HTML / CSS integration.
    [*] Many languages ​​can be transpiled into JavaScript to provide additional functionality. It is recommended that you review them at least briefly after mastering JavaScript.
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.