<script type="text/javascript">
document.write("Hello DevOpSchool");
</script>
<script src="devops.js" type="text/javascript"></script>
<script> – Opening Script Tag.
src – It’s an attribute of the script.
name.js – This is our script file, which we created. The code of javascript is written inside devops.js.
In which DevOps is the file name, .js is the extension. Javascript has an extension of .js
Type – This is also an attribute of the script tag, it tells the browser that it is javascript. Now it is not necessary to write it, you can leave it if you want.
Text/javascript – It defines what type these documents are.
document.write(“Hello World”); – This is a function which is displaying the data.
</script> – Closing Script tag.
How to link more than one External?
You can link more than one JavaScript file to a single document. Just need to write different script tags for that.
<script src="devops1.js" type="text/javascript"></script>
<script src="devops2.js" type="text/javascript"></script>
<script src="devops2.js" type="text/javascript"></script>
<script src="devops3.js" type="text/javascript"></script>
How to use inline and External together in javascript?
No, both cannot be written together. But both inline and external can be written separately.
<!DOCTYPR>
<HTML>
<head><title></title>
</script>
</head>
<body>
<h1>I am Heading</h1>
<p>I am Paragharph</p>
<script type="text/javascript">
document.write("Hello Vijay");
</script>
<br>
<script src="devops.js" type="text/javascript"></script>
</body>
</html>
Write funtion
This function is used to write arbitrary HTML and content into the page. If we use this function after an HTML document is fully loaded, will delete all existing HTML. It is used only for testing purposes.
Ex:- document.write("Hello world");
document.write(variable);
document.write(4+2);
document.write("hello world . <br>");
document.write("hello world . <br>" + variable +"<br>");
Alert function in JavaScript
The data that will be displayed in it will be in the dialog box. You forcefully want to see this thing, then only this work will be done. In that case, you use a window. alert
Ex:- window.alert("Hello World");
window.alert(variable);
window.alert(4+2);
window.alert("hello world"+ variable);
<html>
<head><title>Hello JS</title>
<script>
window.alert("Hello");
</script>
</head>
</body>
` <h1>I am heading</h1>
<p>I am Paraghraph</p>
<script src="name.js" type="text/javascript">
</script>
</body>
</html>
Identifier
An identifier is a name having a few letters, numbers, and special characters _(underscore). It is used to identify a variable, function, symbolic constants, and so on.
Ex:- X2
PI
Sigma
Matadd
Veriable in JavaScript
Variable can be any name, in which a combination of letters, numbers, and special characters can be written _()(underscore) and $(dollar). It is not necessary that there should be only a combination, it can only be a letter.
Ex:- c, fact, b33, total_amount ect.
Rules of Veriable in JavaScript
- Variable can contain a combination of letters, digits, _()(underscore), and dollar signs($).
- Must begin with a letter A-Z or a-z or underscore or dollar sign.
- A variable name cannot start a number.
- Must not contain any space characters.
- JavaScript is case-sensitive
- Can’t use reserved keywords.
Reserved Keyword in javascript
Keyword or Reserved words
var | delete | for | let | brack |
super | void | case | do | static |
function | new | switch | while | interface |
catch | else | if | package | finally |
this | with | class | enum | default |
implements | private | throw | tiled | typeof |
const | export | import | protected | return |
true | continue | extends | in | |
instanceof | ||||
public | try | debugger | false |