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 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #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

#Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS? #Jan 8 How to Install Xcode Command Line Tools on MacOS?
You might also like these
What is Hoisting in JavaScript?JavaScriptUse SwiperJS to create mobile touch sliders fastMiscellaneousCheck If a String Contains a Specific Word in PHPPHPDISTINCT ON: The confusing, unique and useful feature in PostgresPostgresA Step by Step Guide to Make RSS in XML For Any Website or Blog For FreeMiscellaneousHow to create a circle that follows a cursor using JavaScript and CSS?CSS