1. JavaScript Values
Basically In JavaScript values are of two categories.
- Primitive Types
- Reference Types
1.1 Primitive Types
- Number
- Boolean
- String
- Undefined, etc.
Primitive Type | Description |
---|---|
Number | All the numbers are of Number type. |
Boolean | Boolean values are either true or false. |
String | String is a stream of characters. The String should be enclosed with Single quotes, Double quotes, or Backticks. |
Undefined | If a value is not assigned to the variable, then it takes undefined as its value. In JS, undefined refers to the value that is not being assigned. |
1.2 Operators
1.2.1 typeof()
The
typeof()
operator is used to find the type of value.JAVASCRIPT
Try out changing the different Values in the below Code Playground and check the output in the console.
let isApproved = false; console.log(typeof(isApproved)); console.log(typeof(true));
2. Converting String to a Number
In JavaScript, when we combine the number and string, it results in a string.
The
parseInt()
function accepts a string and converts it into an integer.
JAVASCRIPT
3. Conditional Statements
The Conditional Statement allows you to execute a block of code only when a specific condition is true.
If...Else Statement:
Syntax:
JAVASCRIPT
Try out changing the colors, increment, and decrement Values in the below Code Playground and check the output.