#1. JavaScript Numbers
JavaScript has only one type of number. Numbers can be written with or without decimals.
#2. JavaScript Strings
Strings store text. Strings are written inside quotes. You can use single or double quotes:
#3. JavaScript Objects
You have already learned that JavaScript variables are containers for data values.
Objects are variables too. But objects can contain many values.
#4. JavaScript Arrays
JavaScript arrays are used to store multiple values in a single variable.
#6. JavaScript Functions
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
@javascript_tut
"w3schools .com"
JavaScript has only one type of number. Numbers can be written with or without decimals.
#2. JavaScript Strings
Strings store text. Strings are written inside quotes. You can use single or double quotes:
#3. JavaScript Objects
You have already learned that JavaScript variables are containers for data values.
Objects are variables too. But objects can contain many values.
#4. JavaScript Arrays
JavaScript arrays are used to store multiple values in a single variable.
#6. JavaScript Functions
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
@javascript_tut
"w3schools .com"
📌 JavaScript Output
JavaScript can "display" data in different ways:
#1 Using innerHTML
Writing into an HTML element
#2 Using document.write()
Writing into the HTML output
#3 Using alert()
Writing into an alert box
#4 Using console.log()
Writing into the browser console
@javascript_tut
"w3schools .com"
JavaScript can "display" data in different ways:
#1 Using innerHTML
Writing into an HTML element
#2 Using document.write()
Writing into the HTML output
#3 Using alert()
Writing into an alert box
#4 Using console.log()
Writing into the browser console
@javascript_tut
"w3schools .com"
📕Example: for #innerHTML
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const txt = "Hello, World";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
@javascript_tut
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const txt = "Hello, World";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
@javascript_tut
📕Example: for #document.write()
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<script>
var txt = "Hello, World";
document.write(txt);
</script>
</body>
</html>
@javascript_tut
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<script>
var txt = "Hello, World";
document.write(txt);
</script>
</body>
</html>
@javascript_tut
📕Example: for #alert()
-----------------------------------
<!DOCTYPE html>
<html>
<body>
Hello
<script>
var txt = "Hello";
alert(txt);
</script>
</body>
</html>
@javascript_tut
-----------------------------------
<!DOCTYPE html>
<html>
<body>
Hello
<script>
var txt = "Hello";
alert(txt);
</script>
</body>
</html>
@javascript_tut
📕Example: for #console.log()
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<script>
console.log("GeeksforGeeks");
</script>
</body>
</html>
@javascript_tut
-----------------------------------
<!DOCTYPE html>
<html>
<body>
<script>
console.log("GeeksforGeeks");
</script>
</body>
</html>
@javascript_tut
JavaScript Arrays
JavaScript arrays are used to store multiple values in a single variable.
What is an Array?
📌An array is a special variable, which can hold more than one value at a time.
If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:
----------------------------
var car1 = "Saab";
var car2 = "Volvo";
var car3 = "BMW";
----------------------------
However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?
The solution is an array!
📌An array can hold many values under a single name, and you can access the values by referring to an index number.
@javascript_tut
"w3schools .com"
JavaScript arrays are used to store multiple values in a single variable.
What is an Array?
📌An array is a special variable, which can hold more than one value at a time.
If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:
----------------------------
var car1 = "Saab";
var car2 = "Volvo";
var car3 = "BMW";
----------------------------
However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?
The solution is an array!
📌An array can hold many values under a single name, and you can access the values by referring to an index number.
@javascript_tut
"w3schools .com"
Creating an Array
📌Using an array literal is the easiest way to create a JavaScript Array.
Example:
-----------------------------
var cars = [
"Saab",
"Volvo",
"BMW"
];
-----------------------------
📌Using the JavaScript Keyword new
The following example also creates an Array, and assigns values to it:
-----------------------------
var cars = new Array("Saab", "Volvo", "BMW");
-----------------------------
The two examples above do exactly the same. There is no need to use new Array().
For simplicity, readability and execution speed, use the first one (the array literal method).
@javascript_tut
"w3schools .com"
📌Using an array literal is the easiest way to create a JavaScript Array.
Example:
-----------------------------
var cars = [
"Saab",
"Volvo",
"BMW"
];
-----------------------------
📌Using the JavaScript Keyword new
The following example also creates an Array, and assigns values to it:
-----------------------------
var cars = new Array("Saab", "Volvo", "BMW");
-----------------------------
The two examples above do exactly the same. There is no need to use new Array().
For simplicity, readability and execution speed, use the first one (the array literal method).
@javascript_tut
"w3schools .com"
JavaScript Comments
📌JavaScript comments can be used to explain JavaScript code, and to make it more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
💎Single Line Comments
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
💎Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
@javascript_tut
"w3schools .com"
📌JavaScript comments can be used to explain JavaScript code, and to make it more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
💎Single Line Comments
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
💎Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
@javascript_tut
"w3schools .com"
📌Tutorials based on web development and programming.
💻 + Source Code
⚙️ Html, CSS, JavaScript, React , Bootstrap, jQuery, AJAX, PHP, java, Python, SQL, MYSQL, Node.js, JSON, and More...
💙 Subscribe for More Tutorials:
https://www.youtube.com/codingwithelias?sub_confirmation=1
💻 + Source Code
⚙️ Html, CSS, JavaScript, React , Bootstrap, jQuery, AJAX, PHP, java, Python, SQL, MYSQL, Node.js, JSON, and More...
💙 Subscribe for More Tutorials:
https://www.youtube.com/codingwithelias?sub_confirmation=1
JavaScript Syntax
💎JavaScript syntax is the set of rules, how JavaScript programs are constructed:
📌JavaScript Values
The JavaScript syntax defines two types of values:
💎Fixed values are called Literals.
JavaScript Literals
The two most important syntax rules for fixed values are:
1. Numbers are written with or without decimals:
2. Strings are text, written within double or single quotes:
💎Variable values are called Variables.
In a programming language, 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.
@javascript_tut
"w3schools .com"
💎JavaScript syntax is the set of rules, how JavaScript programs are constructed:
📌JavaScript Values
The JavaScript syntax defines two types of values:
💎Fixed values are called Literals.
JavaScript Literals
The two most important syntax rules for fixed values are:
1. Numbers are written with or without decimals:
2. Strings are text, written within double or single quotes:
💎Variable values are called Variables.
In a programming language, 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.
@javascript_tut
"w3schools .com"
JavaScript Operators
JavaScript uses arithmetic operators ( + - * / ) to compute values:
JavaScript uses an assignment operator ( = ) to assign values to variables:
@javascript_tut
"w3schools .com"
JavaScript uses arithmetic operators ( + - * / ) to compute values:
JavaScript uses an assignment operator ( = ) to assign values to variables:
@javascript_tut
"w3schools .com"