Introduction Flashcards

1
Q

Programs in JS are called what ?

A

Scripts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can we write JS scripts directly into the html ?

A

They can be written right in a web page’s HTML and run automatically as the page loads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do scripts need compilation before running ?

A

Scripts are provided and executed as plain text. They don’t need special preparation or compilation to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What we need to run a JS program ?

A

Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called the JavaScript engine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The browser has an embedded engine sometimes called ?

A

“JavaScript virtual machine”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Examples of some JS engines in browsers today ?

A

V8 – in Chrome, Opera and Edge.
SpiderMonkey – in Firefox.
…There are other codenames like “Chakra” for IE, “JavaScriptCore”, “Nitro” and “SquirrelFish” for Safari, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Briefly explain how the JS engine works ?

A

Engines are complicated. But the basics are easy.

The engine (embedded if it’s a browser) reads (“parses”) the script.
Then it converts (“compiles”) the script to the machine language.
And then the machine code runs, pretty fast.
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and further optimizes the machine code based on that knowledge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do JS provides low-level access to memory to CPU ?

A

Modern JavaScript is a “safe” programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

can we do webpage manipulation, interaction with the user and webserver with in-browser javascript ?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to add new HTML to the page, change the existing content, modify styles.

A

we can do it with in browser js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which type of js can React to user actions, run on mouse clicks, pointer movements, key presses.

A

In-browser JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which JS can Send requests over the network to remote servers, download and upload files (so-called AJAX and COMET technologies).

A

IN browser JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which JS can Get and set cookies, ask questions to the visitor, show messages.

A

In browser JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which JS can Remember the data on the client-side (“local storage”).

A

In browser JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

can In browser JavaScript on a webpage read/write arbitrary files on the hard disk

A

JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions.

Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like “dropping” a file into a browser window or selecting it via an tag.

There are ways to interact with camera/microphone and other devices, but they require a user’s explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the NSA.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is same origin policy ?

A

Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites (from a different domain, protocol or port).

This is called the “Same Origin Policy”. To work around that, both pages must agree for data exchange and contain a special JavaScript code that handles it. We’ll cover that in the tutorial.

This limitation is, again, for the user’s safety. A page from http://anysite.com which a user has opened must not be able to access another browser tab with the URL http://gmail.com and steal information from there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

can two different sites(having different servers) communicate with each other using JS

A

JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that’s a safety limitation.

Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugin/extensions which may ask for extended permissions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How languages over JS like typescript or coffeeScript works ?

A

The syntax of JavaScript does not suit everyone’s needs. Different people want different features.

That’s to be expected, because projects and requirements are different for everyone.

So recently a plethora of new languages appeared, which are transpiled (converted) to JavaScript before they run in the browser.

Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another language and auto-converting it “under the hood”.

19
Q

What is the significance of script tag ?

A

The tag contains JavaScript code which is automatically executed when the browser processes the tag.

20
Q

Where is the file located ?

src=”picture.jpg”

A

The “picture.jpg” file is located in the same folder as the current page

21
Q

Location of the file ?

src=”images/picture.jpg”

A

The “picture.jpg” file is located in the images folder in the current folder

22
Q

Location of the file ?

src=”/images/picture.jpg”

A

The “picture.jpg” file is located in the images folder at the root of the current web

23
Q

Location of the file ?

src=”../picture.jpg”

A

The “picture.jpg” file is located in the folder one level up from the current folder

24
Q

What is absolute file paths

A

An absolute file path is the full URL to a file:

25
What is relative file paths ?
A relative file path points to a file relative to the current page. eg-
26
What is the best practice while making file paths ?
It is best practice to use relative file paths (if possible). When using relative file paths, your web pages will not be bound to your current base URL. All links will work on your own computer (localhost) as well as on your current public domain and your future public domains.
27
Why external script files are used in large projects ?
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files. The benefit of a separate file is that the browser will download it and store it in its cache. Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once. That reduces traffic and makes pages faster.
28
What if we have both code inside the script tag and also the src attribute pointing to an external js file ?
A single tag can’t have both the src attribute and code inside. This won’t work: alert(1); // the content is ignored, because src is set We must choose either an external or a regular