Eri's
  • Home
  • Education
  • Entertainment
  • Tech
  • Relationship
  • Motivation
No Result
View All Result
Get Started
Eri's
  • Home
  • Education
  • Entertainment
  • Tech
  • Relationship
  • Motivation
No Result
View All Result
Eris's
No Result
View All Result
How To Write Variables in Different Programming Languages

How To Write Variables in Different Programming Languages

admin by admin
June 7, 2022
in Tech, Uncategorized
Reading Time: 5 mins read
A A
0
Share on FacebookShare on Twitter

Hey guys

In today’s lesson, we will walk through how to write variables in 7 different programming languages. Since variables in programming are indispensable when coding.

You might also like

COMPARE TRIPLETS HACKERRANK SOLUTION

August 8, 2022
nike shoe bag

Nike Shoe Bag – The reasons why you need a Nike shoe bag.

June 6, 2022

What Are Variable in Programming?

Variables are just a way to save data or information for usable purposes. Variable makes a program to be more clear to read by the coder

and others. All programming languages have their own way to write and execute a  variable.

Nevertheless, am going to mention how to write a variable in PHP, JavaScript, Python, Java, C#, C++, and CSS.

1. How To Write a Variable in JavaScript

JavaScript accepts a string, integer, float, Boolean, etc. to be stored in a variable. Variable can be declared in JavaScript using let , constand var. The const is sometimes referred to as constant in JavaScript.

Let’s Do Some Example

JavaScript Variables

Using the var , let and const to declare different type of Data types in JavaScript Respectively.

 


var strg= "Erisanal.com" 
const num = 100 
let bolln = true 

console.log(strg) //Output Erisanal.com
console.log(num) //Output 100
console.log(bolln) //Output true

2. How To Write a Variable in PHP

To declare a variable in PHP, you must start with the $ sign followed by the name of the variable, the equal to sign =is used to assign value to the variable name.

Let’s do an example

PHP Variable

<?php
// Declaring variables
$txt = "Hello World!";
$num = 100;
 
// Displaying variables value
echo $txt;  // Output: Hello World!
echo $num; // Output: 100;

?>

2. How to declare a constant variable in PHP

Unlike JavaScript, the const keyword is used to define a constant variable, but in PHP is completely different. Thedefine( ) function is used to define a varibale in PHP whick takes three parameters as an argument.

Syntax

define(name, value, case-insensitive)

PHP define( ) Parameter Explained

  • name: This is the first parameter that serves as the name of your variable
  • value: This is the data you want to store in the variable, this can be an integer, boolean strings, or any PHP data types.
  • case-insensitive: This is optional, this is used to enable and disable case-sensitive and case-insensitive respectively. This parameter only accepts a boolean value (i.e true or false). The default is false which means the variable is case-insensitive. To enable case-sensitive change to true.

Let’s create a PHP constant with a case-sensitive name:

Example One.

<?php
define("Name", "Erisanal.com", true);
echo Name;
?>

Let’s create a PHP constant with a case-insensitive name:

Example Two

<?php
define("Name", "Erisanal.com", false);
echo Name;
?>

// The above code can also be written as:

<?php
define("Name", "Erisanal.com");
echo Name;
?>

3. How To Write a Variable in Python

Since Python is completely object-oriented, and not “statically typed”, it doesn’t have a command you can use to declare a variable. A python variable is declared once you have added value to it.

To assign a value to a python variable, use the equal to = sign


strg= "Erisanal.com" 
num = 100 

print(strg) #Output Erisanal.com
print(num) #Output 100

How to declare a constant variable in Python

In python, there is no support for constant variables, hence constant variables can’t be declared in python.

4. & 5. How To Write a Variable in C++ and C#

Declaring a variable in C++ and C# is strict.  both languages executes it’s variable in almost the same way.

To declare a variable in C++, and C#, the type must be specified before you assign a value to it. There are different type of variable in C++ and C#, some of these are:

  • String – Are text that is surrounded by a double quote e.g “Hello World !”
  • int – This is is an integer, sometimes referred to as whole numbers. Numbers without decimal such as 987, -987
  • double – is a decimal number e.g 987.00 or -987.00
  • char – stores single characters that are surrounded by a single quote e.g ‘Z’ or ‘a’
  • bool – stores boolean value such as true and false only

Declaring a Variable in C++, and C#

Generally, All programming languages abide to using the equal to sign = to declare a variable.

Syntax

type variable = value;

Now, let’s move by creating different types of variable

C++, and C# Variable

String myWebsite = "Erisanal.com";
char myLetter = 'E';
int myNum = 905;
float myFloatNum = 2.99f;
boolean isBool = false;

6. How to declare a Variable in Java

To declare a variable is almost the same as to declare a C++ and C# variable, All these programming languages require the data type to be specified before you assign a value to it.

The difference lies in the variable type. In Java, this is how the variable type can be declared.

  • String – Are text that is surrounded by a double quote e.g “Hello World !”
  • int – This is is an integer, sometimes referred to as a whole number. Numbers without decimals such as 987, -987
  • float – is a decimal number e.g 987.00 or -987.00
  • char – stores single characters that are surrounded by a single quote e.g ‘Z’ or ‘a’
  • boolean – stores boolean values such as true and false only

Declaring Java Variable

Example

int myNum;
myNum = 15;
System.out.println(myNum); //Output 15

7. How To Write a Variable in CSS

CSS also has a way it executes a variable. To declare a CSS variable is different from other programming languages variable. In most programming languages, the equal to = sign is used to assign a value to the variable while in CSS is entirely unlike.

How to Declare a CSS Variable

The column : sign is used to a assign value instead. The CSS variable is usually defined within the CSS :root { } pseudo-class.

A CSS variable usually starts from -- followed by the variable name. The var ( ) function is used to call and execute a CSS variable

Let’s quickly do an example

CSS Variable

:root {
--color : #3e5afb
}

/* Calling a CSS variable

body { 
color: var(--color)
}

Conclusion

These are how variables is been declared in the programming languages mentioned. Hope you enjoyed this post, Share your thought by commenting.

Tags: tech
ShareTweetPin
Previous Post

Nike Shoe Bag – The reasons why you need a Nike shoe bag.

Next Post

Capetown Diamond – The most successful diamond store.

admin

admin

Related Stories

COMPARE TRIPLETS HACKERRANK SOLUTION

by bankole idris
August 8, 2022
1

PROBLEM STATEMENT: Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on...

nike shoe bag

Nike Shoe Bag – The reasons why you need a Nike shoe bag.

by Holar Dee
June 6, 2022
0

Nike Shoe Bag The Nike shoe bag - Almost all Nike shoes are manufactured outside the United States. The top...

Campfire Spray – Things You Need to Know Before You Buy Or Use It

by admin
June 5, 2022
0

Campfire spray is one of the best sprays you would want to use, but it is advisable to know these...

olumo rock

6 Most Beautiful Natural Places In Nigeria

by admin
June 6, 2022
0

Since I was born, I have been hearing a saying that ” Nigeria is the  Giant of Africa”. Well, I...

Next Post
Capetown Diamond

Capetown Diamond - The most successful diamond store.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Erisanal

We bring you relevant post on tech and educational content

  • Contact Us
  • Terms And Conditions
  • Privacy And Policy
  • About Us

Categories

  • Culture
  • Education
  • Entertainment
  • How to
  • Motivation
  • Product Review
  • Quote
  • Quotes
  • Relationship
  • Tech
  • Uncategorized

© copyright 2022 Eri's.

No Result
View All Result
  • Home
  • Education
  • Relationship
  • Tech

© copyright 2022 Eri's.