JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities.
💥why use JavaScript
JavaScript is one of the 3 languages all web developers must learn:
1. HTML to define the content of web pages
2. CSS to specify the layout of web pages
3. JavaScript to program the behavior of web pages
💥Where to use Java Script
💢 In HTML, JavaScript code must be inserted between <script> and </script> tags.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
💢Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.
<head> <script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script> </head>
<body>
<p id="demo"></p>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</body>
💢 Scripts can also be placed in external files
external files has some advantages:
- It separates HTML and code
- It makes HTML and JavaScript easier to read and maintain
- Cached JavaScript files can speed up page loads
<script src="myScript1.js"></script>
<script src="myScript2.js"></script>
💥JavaScript can "display" data in different ways
- Writing into an HTML element, using innerHTML.
- Writing into the HTML output using document.write().
- Writing into an alert box, using window.alert().
- Writing into the browser console, using console.log().
💥JavaScript syntax is the set of rules, how
JavaScript programs are constructed.
💥JavaScript statements are composed of:
Values, Operators, Expressions, Keywords,
and Comments.
💥The JavaScript syntax defines two types of values: Fixed values and variable
values.
Fixed values are called literals. Variable values are called
variables.
💥 Java Script Variables
variables
are used to store data values.
JavaScript uses the var keyword to declare variables.
An equal sign is used to assign values to variables.
Eg:
<script>
var x;
x = 6;
document.getElementById("demo").innerHTML = x;
</script>
💢 The values can be of various types, such as numbers and strings.
Eg: "John" + " " + "Doe", evaluates to "John Doe"
💥Java Script Comments
Code after double slashes
// or between /* and */ is treated as a comment
💥JavaScript is Case Sensitive
All JavaScript identifiers are case sensitive.The variables lastName and lastname, are two different variables.
Eg:
<script>
var lastname, lastName;
lastName = "Doe";
lastname = "Peterson";
document.getElementById("demo").innerHTML = lastName;
</script>
out put: Doe
💥Java Script is Camel Case
Hyphens
first-name, last-name, master-card, inter-city.
👱 Hyphens are not allowed in JavaScript. It is reserved for subtractions.
Underscorefirst_name, last_name, master_card, inter_city.
Upper Camel Case
FirstName, LastName, MasterCard, InterCity.
Lower Camel Case
use camel case that starts with a lowercase letter
firstName, lastName, masterCard, interCity.
No comments:
Post a Comment