Javascript Control flow

Data Types:

Strings:

  • Used to represent text.
  • Enclosed in single (') or double (") quotes.
                                  
                                    let greeting = "Hello, World!";
let name = 'John';                    
                                  
                                

Numbers:

Represents numeric values, including integers and floating-point numbers.

                                  
                                    let count = 10;
let pi = 3.14;
                                  
                                

Booleans:

Represents true or false values.

                                  
                                    let isTrue = true;
let isFalse = false;
                                  
                                

Type Coercion:

Type coercion refers to the automatic or implicit conversion of one data type to another.

JavaScript will try to make sense of operations even if they involve different data types.

Implicit Coercion:

                                  
                                    let num = 5;
let str = "10";

let result = num + str;
console.log(result); // "510" (string concatenation)              
                                  
                                

In this example, the num variable is implicitly coerced into a string when it's added to the string str.


Explicit Coercion:

                                  
                                    let num = 5;
let str = "10";

// Using parseInt for explicit coercion
let result = num + parseInt(str);
console.log(result); // 15 (numeric addition)
                                  
                                

Here, parseInt is used to explicitly coerce the string str into a number before performing the addition.


Hey there! Let's go for Learn fasta then! It is more than just coding; it is to have the superpower that can solve any problem. Through simple and easy-to-grasp examples you will sail through the learning process. In addition, it is not just about coding– you will acquire competencies on how to solve complex problems, analyze data, and come up with efficient solutions. Shall we start this wonderful journey together! learnfasta.com terms of use, Copyright 2025 All Rights Reserved.