JavaScript is one of the top 3 languages a web developer must learn. JavaScript is a programming language that programs the behavior of web pages.
JavaScript is the world's most popular programming language.
JavaScript is the programming language of the Web.
JavaScript is easy to learn.
One of the most useful JavaScript HTML method is the getElementByID().
An example of this working is:
document.getElementById(“erovoutika”).innerHTML = “Hello Erovoutika!”
The example above selects the element with the id of “erovoutika” and changes the content of it to “Hello Erovoutika!”.
An example of this working is:
document.getElementById(“erovoutika”).style.fontSize = “35px”;
The example above changes the style attribute, specifically, the font size of the element to 35px making the element font larger.
To demonstrate:
document.getElementById (“erovoutika”).style.display = “none”;
The example above hides the element with an ID of “erovoutika” by changing the style attribute, specifically the display style of the element to none. For showing the element again, we are just going to bring back the display of the style attribute to "block".
To demonstrate:
document.getElementById (“erovoutika”).style.display = “block”;
To demonstrate:
<!DOCTYPE html>
<html>
<head>
<script>
function erovoutikaFunc(){
document.getElementById(“Erovoutika”).innerHTML = “Hello Erovoutika”;
}
</script>
</head>
<body>
<p id="Erovoutika">Hello World!</p>
<button type="button" onclick="erovoutikaFunc()">Click</button>
</body>
</html>
This is the content of the External file named: myExternalScript.js
function erovoutika Function(){
document.getElementById(“erovoutika”).innerHTML = “General Erovoutika”
}
And this is the content of the main file:
<body>
<p id="erovoutika"></script>
<button type="button" onclick="erovoutikaFunction()">Click Me!</button>
<script src=”myExternalScript.js”></script>
</body>
The result of this code will be, upon clicking the button, the Hello There! Should be replaced with General Erovoutika.
You can also use the src attribute to reference JavaScript files from the web! As long as you entered the correct web address.
With each of them having their advantages, like the console.log() is super helpful for debugging codes
The most important syntax for Fixed Values or Literals are Numbers and Strings.
Variables are values that store data values. JavaScript uses the let, var, and const keywords to declare its variables.
To demonstrate:
let x = 10;
var y = 11;
To explain the code above, the we declared that x should have a value of 10 and that y with a value of 11.
// console.log(“I’ll not be printed”)
console.log(“I’ll be printed”)
To explain the code above, the first console.log will not be printed since we put a double slash at the beginning of the line. You can also use a slash asterisk (/*) and asterisk slash (*/) to comment out multi-line block of code.
JavaScript is a case-sensitive language meaning that firstName and firstname is not considered as a same variable.
(1 + 1) * 2
In an earlier example, you’ll see that we used = to declare the value of x, this is called assignment operator
In an earlier example, you’ll see that we used = to declare the value of x, this is called assignment operator
function erovoutikaFunction(e1, e2){
return e1 + e2;
}
console.log(erovoutikaFunction(1, 2)) // 3
To explain the code above, the function erovoutikaFunction returns the sum of the two variables that the user have inputted within the function’s parameter.
objectName.propertyName or objectName[“propertyName”]
ErovoutikaIntern.fullName(); // John Doe
To explain the code above, the fullName method takes the firstName and lastName property of the erovoutikaIntern object.
Note: if you call the function without the parenthesis, it will show the method definition instead.
const erovoutikaIntern = { firstName: “John”,
lastName: “Doe”,
contactNumber: “09952112978” };
const erovoutikaIntern = { firstName: “John”,
lastName: “Doe”,
fullName: function() {return this.firstName + “ “ + this.lastName};
var isDayTime = true
if (isDayTime == true) {
console.log(“Its daytime!”);
}
To explain the code above, the if condition checks if the variable isDayTime is true, which it is, so it will pass through this condition and outputs Its daytime!
var isDayTime = true
if (isDayTime == true) {
console.log(“Its daytime!”);
} else {
console.log(“Its nighttime!”);
}
To explain the code above, the if condition checks if the variable isDayTime is true, which is not true! So it moves to the else block where it outputs Its nighttime!.
var myNum = 5
if (myNum > 6) {
console.log(“Im greater!”)
}
else if (myNum < 6) {
console.log(“Im here!”)
}
To explain the code above, the if condition checks if the variable myNum is true, which is not! So it moves to the next condition in else if, upon checking, its true! So it will output Im here!.