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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #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
You might also like these
Use SwiperJS to create mobile touch sliders fastMiscellaneousHow to invalidate all existing cookies using Security Keys in WordPress?WordPressWhat’s a Strict mode in JavaScript?JavaScriptsubstring() Method in JavaScriptJavaScriptHow to add Laravel to WordPress using Sage theme (and install Tailwind CSS)?PHPfor @each loop in SCSSSCSS