JS Fundamentals - Hello World Flashcards

1
Q

Ancient way of commenting code inside js script tag

A

In really ancient books and guides, you may find comments inside tags, like this:

This trick isn’t used in modern JavaScript. These comments hide JavaScript code from old browsers that didn’t know how to process the tag. Since browsers released in the last 15 years don’t have this issue, this kind of comment can help you identify really old code.

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

External Script

A

Here, /path/to/script.js is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, src=”script.js” would mean a file “script.js” in the current folder.

We can give a full URL as well. For instance:

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

To attach multiple scripts

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

what is the benefit of keeping external scripts

A

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.

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

If src is set, the script content is ignored.

A

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

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

Summary

A

We can use a tag to add JavaScript code to a page.
The type and language attributes are not required.
A script in an external file can be inserted with .

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