Introduction to JavaScript
Introduction to JavaScript
Output
• Writing into an HTML element, using innerHTML.
Program / Statement
A computer program is a list of "instructions" to be "executed" by a
computer. In a programming language, these programming instructions are called
statements. A JavaScript program is a list of programming statements.
JavaScript Statements. JavaScript statements are composed of: Values,
Operators, Expressions, Keywords, and Comments.
JavaScript programs (and JavaScript statements) are often called JavaScript
code.
Semicolon ( ; )
This separates JavaScript statements:
Multiple Lines
</script>
Single Line
<p id = "demo1"> </p>
<script>
let a, b, c;
a = 5; b = 6; c = a + b;
document.getElementById("demo1").innerHTML = c;
</script>
</script>
JavaScript Keywords
JavaScript statements often start with a keyword to identify the JavaScript
action to be performed.
Keywords Descriptions
var Declares a variable, but same usage as
let
let Declares a block variable, but same
usage as var
const Declares a block constant
if Marks a block of statements to be
executed on a condition
JavaScript Values
The JavaScript syntax defines two types of values:
• Fixed Values are called Literals. – You are just declaring values to your code.
Can be numbers (whole or with decimal) & string (single or double quoted).
</script>
JavaScript Operators
!!NOTE – Remember PEMDAS in using these operators.
Operators Description
+ Addition
- Subtraction
* Multiplication
/ Division
= Assign
JavaScript Expressions
An expression is a combination of values, variables, and operators, which
computes to a value. The computation is called an evaluation.
Number to Number:
Variable to Number:
</script>
</script>
JavaScript Comment
Commenting is same as in C++ // and /* */ but will be used inside the
<script> tag.