In Continuation of my last post on JavaScript Data types, let's look into the remaining data types in JavaScript.
Note: Floats are numbers that have decimal points or fractional parts while Integers are whole numbers or numbers that don't have decimal points.
JavaScript Data Types
-
Boolean:
This is used to execute conditional logic ( 1 or 0) that is True or false. -
Undefined:
This is used to show that a particular variable doesn't have a value yet ( it has been declared but hasn't been initialized. -
Null:
Doesn't have a value ( it will not have a value) -
NaN:
It means Not a Number, When an arithmetic operation cannot give you a number is called NaN data type. -
Void:
Is a data type that shows when a function doesn't return a value. -
Bigint:
Big integers
Two ways of accessing the value of an object Data types are " Bracket notation and Dot notation.
Example.
Let student id = Student {"reg-number"}
( This is the bracket notation)
Let student name = Student.name
( This is the dot notation)
Functions:
Functions perform a single task and it works with parameter and argument, Parameters is when you are "Defining" a function while "Calling" a function is an Argument.
Let name;
name = "John"
Concatenation is adding two or more strings together
Arithmetic operators and logical operators and Logical statements.
- , - , / , * , % are Arithmetic operators
< , > , >= , <= , != , == , === , are Relational or comparators operators
! , && , I I , are Logical operators
Methods of JavaScript:
- Alert ( ) This is a method that shows a pop up message in the browser.
- Prompt ( ) This is a method that shows a pop up asking for an input in the browser
Conditional statements.
Conditional statements are used to control the flow of a program based on specific conditions or decisions.
Types of Conditional Statements:
-
If Statement: Used to execute a block of code if a condition is true.
-
If-Else Statement: Used to execute one block of code if a condition is true and another block of code if the condition is false.
-
If-Else If Statement: Used to check multiple conditions and execute different blocks of code based on the conditions.
-
Switch Statement: Used to execute different blocks of code based on the value of a variable or expression.