Yogesh Chauhan's Blog

What is the difference between Loosely Typed Language and Strongly Typed Language?

in Miscellaneous on November 4, 2019

In a loosely typed language, we are NOT required to define the type of a variable while declaring it.

For example, Perl and PHP. They both are a loosely typed languages. We can declare a variable without specifying the type of a variable. A loosely typed language automatically associates a data type to the variable, depending on the value of a variable.

For example, take a look at the following variable declarations. In the first line we have declared a variable named $var1, which can be used as an integer or string later on.

var $var1;
$var1 = 1; #var1 variable is now integer.
$var1 = "hello"; #var1 variable is now a string.

Strongly typed language is the opposite of a loosely typed language for example C.

Any programming language which requires a variable type to be defined is a strongly typed language. For example, programming language C is a strongly typed language as you must specify the type of the variable when declaring it.

Let's take a look at the example below. We are declaring the same variable var1 as an integer in the first line but in the second line we have to change the type to a floating point in order to change the value and same in the third line we are changing the type to char to assign a character value.

int var1 = 25;
float var1 = 2.3;
char var1 = 'e';

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
IN Operator in PostgreSQLPostgresObject destructuring in JavaScript: Unpacking fields from objects passed as function parameterJavaScriptWhat are components in Angular?AngularUse inline if to make a shorter conditional syntax in ReactReactHow to get Current Hour, Minute and Second in JavaScript?JavaScriptINNER JOIN in PostgresPostgres