1_introduction_to_javascript_1786795721
1_introduction_to_javascript_1786795721
1 Introduction to Javascript
Table of Content
1. What is Javascript
1. What is Javascript
JavaScript (JS) is a high-level, interpreted, dynamic programming language
primarily used to create interactive and dynamic web content. It is one of the
core technologies of the web, alongside HTML and CSS.
Compiler or Interpreter?
JavaScript is both interpreted and compiled, depending on the context:
<script>
document.getElementById("demo").innerHTML = "My First JavaS
</script>
<script src="myScript1.js"></script>
Keywords
Javascript Statements
Note: It is recommended we use let instead of var. However, there are a few
browsers that do not support let.
//valid
let a = 'hello';
let _a = 'hello';
let $a = 'hello';
//invalid
Let 1a = 'hello'; // this gives an error
let y = "hi";
let Y = 5;
console.log(y); // hi
console.log(Y); // 5
//invalid
let new = 5; // Error! new is a keyword.
Number()
String()
Boolean()
Note:
3. In JavaScript, undefined , null , 0 , NaN , '' converts to false. All other values
give true .
const number = 3 + 5; // 8
ternary Operator
The ternary operator takes three operands, hence, the name ternary
operator. It is also known as a conditional operator.
If-else, else-if
In computer programming, there may arise situations where you have to run
a block of code among more than one alternatives. For example, assigning
grades A, B or C based on marks obtained by a student.
In such situations, you can use the JavaScript if...else statement to create
a program that can make decisions.
if (condition) {
// block of code if condition is true
} else {
// block of code if condition is false
}
You can also write multiple else if in between the if and the else blocks.
logical Operators
switch (a) {
case 1:
a = 'one';
break;
case 2:
a = 'two';
break;
default:
a = 'not found';
break;
}
console.log(`The value is ${a}`);