Exploring "Hello World" Across C#, JavaScript, Python, and TypeScript

Exploring "Hello World" Across C#, JavaScript, Python, and TypeScript

March 24, 2025
1
2
0

"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 (void here) 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 function keyword (or arrow functions for modern syntax).
  • Variable Naming: Variables use camelCase (message), declared using let, const, or var.
  • 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

LanguageFunction KeywordVariable ConventionOutput Method
C#void & class-basedcamelCaseConsole.WriteLine()
JavaScriptfunctioncamelCaseconsole.log()
Pythondefsnake_caseprint()
TypeScriptfunction + type annotationscamelCase + typedconsole.log()

Conclusion

Through 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.


Razz
Razz

I'm Razz! I'm a programmer first, and hope to share some of that knowledge in posts here! I am to break down and post about cool functions and methods that I think are useful, and demystifying the magic of languages from C# to JavaScript!

Comments:

1 Comment

Please be kind and respectful to others. Abusive comments will lead to a ban.

Default profile
BladeRunner 1 year ago

C'est vraiment utile. Merci!

0
0