Exploring "Hello World" Across C#, JavaScript, Python, and TypeScript
"Hello World" Across Four Programming Languages
When diving into programming, the "Hello World" example serves as a fun, straightforward introduction to understanding how a language works. From function definitions to variable naming conventions, each programming language has its unique style. Let’s explore this concept using four popular languages: C#, JavaScript, Python, and TypeScript.
1. Hello World in C#
C# is a statically typed, object-oriented language commonly used for building Windows applications and games. Functions in C# are explicitly declared with a return type and encapsulated within a class.
using System;
class Program
{
// Method to display Hello World
static void DisplayMessage()
{
// Declare a variable to hold the message
string message = "Hello, World!";
Console.WriteLine(message); // Print the message to the console
}
static void Main()
{
DisplayMessage(); // Call the method
}
}
- Function Definition: Functions are defined with a return type (
voidhere) and must be inside a class. - Variable Naming: Variables use camelCase (e.g.,
message). - Console Output:
Console.WriteLine()is used to print to the console.
2. Hello World in JavaScript
JavaScript is a dynamically typed language widely used for web development. Functions are defined using the function keyword or arrow function syntax.
function displayMessage() {
// Declare a variable to hold the message
let message = "Hello, World!";
console.log(message); // Print the message to the console
}
displayMessage(); // Call the function
- Function Definition: Functions are defined with the
functionkeyword (or arrow functions for modern syntax). - Variable Naming: Variables use camelCase (
message), declared usinglet,const, orvar. - Console Output:
console.log()is the standard for logging output.
3. Hello World in Python
Python is a dynamically typed, interpreted language known for its simplicity. Functions are defined using the def keyword.
def display_message():
# Declare a variable to hold the message
message = "Hello, World!"
print(message) # Print the message to the console
display_message() # Call the function
- Function Definition: Functions are defined using
def, and indentation is crucial for defining their scope. - Variable Naming: Python uses snake_case for variable names (
message). - Console Output:
print()is used for printing output.
4. Hello World in TypeScript
TypeScript is a superset of JavaScript, adding static typing and other enhancements. Function syntax is similar to JavaScript but can include type annotations.
function displayMessage(): void {
// Declare a variable with a type annotation
let message: string = "Hello, World!";
console.log(message); // Print the message to the console
}
displayMessage(); // Call the function
- Function Definition: Similar to JavaScript, but type annotations (
: void) can be added for clarity. - Variable Naming: CamelCase is used (
message), with optional type annotations (string). - Console Output: Uses
console.log()like JavaScript.
Comparative Overview
| Language | Function Keyword | Variable Convention | Output Method |
|---|---|---|---|
| C# | void & class-based | camelCase | Console.WriteLine() |
| JavaScript | function | camelCase | console.log() |
| Python | def | snake_case | print() |
| TypeScript | function + type annotations | camelCase + typed | console.log() |
ConclusionThrough the "Hello World" example, we see that each language has its own conventions and strengths. While C# enforces strict structure and type safety, JavaScript offers flexibility with dynamic typing. Python is accessible and clean, while TypeScript combines JavaScript’s syntax with enhanced type safety. By exploring these differences, you’ll gain a foundational understanding to approach coding with confidence in any language. |
Comments:
1 Comment
Please be kind and respectful to others. Abusive comments will lead to a ban.
C'est vraiment utile. Merci!