YogeshChauhan . com

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

in Misc 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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to define constants in PHP?PHPHow to scroll contents of a an element vertically using JavaScript?JavaScriptHow to import a CSS file using PHP code and not HTML code?PHPHow to redirect or load a new document using JavaScript?JavaScriptPostgreSQL BETWEENPostgresUnary Operators in JavaScriptJavaScript