JSCommentsSyntaxGr.7
JSCommentsSyntaxGr.7
10.50
1000
</body>
</html>
// EXAMPLE // OUTPUT
</body>
</html>
JavaScript Literals
The two most important syntax rules for fixed values are:
2. Strings are text, written within double or single quotes:
“John Doe”
‘John Doe’
<h2>JavaScript Strings</h2>
JavaScript Strings
<p> id=“demo”></p>
John Doe
<script>
document.getElementById(“demo”).inn
erHTML = ‘John Doe’;
</script>
</body>
</html>
JavaScript Variables
> In a programming language, variables are used to store data values.
> JavaScript uses the keywords var, let and const to declare variables.
> An equal sign is used to assign values to variables.
> In this example, x is defined as a variable. Then, x is assigned the
value 6.
let x;
Try it Yourself >
x = 6;
// EXAMPLE // OUTPUT
<h2>JavaScript Variables</h2>
JavaScript Variables
<p> id=“demo”></p>
<script> 6
let x;
x = 6;
document.getElementById(“demo”).inn
erHTML = x;
</script>
</body>
</html>
JavaScript Operators
JavaScript uses arithmetic operators (+, -, *, / ) to compute values
(5 + 6) * 10
<h2>JavaScript Operators</h2>
JavaScript Operators
<p> id=“demo”></p>
<script> 110
document.getElementById(“demo”).inn
erHTML = (5 + 6) * 10;
</script>
</body>
</html>
JavaScript uses assignment operators (=) to assign values to variables:
let x, y;
x = 5;
y = 6;
5 * 10 x * 10
<p> Expressions compute to values. </p> <p> Expressions compute to values. </p>
<p> id=“demo”></p> <p> id=“demo”></p>
<script> <script>
document.getElementById(“demo”).innerHTML var x;
= 5 * 10; x = 5;
</script> document.getElementById(“demo”).innerHTML
= x * 10;
</body> </script>
</html>
</body>
</html>
// OUTPUT
JavaScript Expressions
50
JavaScript Keywords
JavaScript keywords are used to identify actions to be performed.
The let keyword tells the The var keyword also tells the
browser to create variables browser to create variables
let x, y; var x, y;
x = 5 + 6; X = 5 + 6;
y = x * 10; y = x * 10;
</body>
</html>
JavaScript Identifiers/Names
Identifiers are used to name variables and keywords,
and functions.
1. Underscore:
• first_name, last_name, master_card, inter_city.
2. Upper Camel Case (Pascal Case):
• FirstName, lastName, masterCard, InterCity.
3. Lower Camel Case:
• firstName, lastName, masterCard, interCity.
Multi-line Comments
• Multi-line commnets start with /* and end with */
• Any text between /* and */ will be ignored by JavaScript.