Episode 1 — .NET / C# for JavaScript Developers: Keywords & Identifiers
Episode 1 — .NET / C# for JavaScript Developers: Keywords & Identifiers
Hey everyone! Welcome to the .NET / C# for JavaScript Developers series. If you know JavaScript and want to learn .NET — this series is made for you!
We will learn every concept by comparing it with JavaScript so you pick it up fast. We will also refer to a real-world ASP.NET Core project (a Benefit Plan Recommendation API) at every step, so nothing feels theoretical.
What we will cover in this series (Roadmap):
.NET / C# Learning Roadmap (JS Developer Edition) ================================================== PHASE 1 — Language Basics -------------------------- Step 1 → Keywords & Identifiers Step 2 → Data Types & Variables Step 3 → Access Modifiers Step 4 → OOP — Classes & Objects Step 5 → OOP — Interfaces Step 6 → OOP — Inheritance & Sealed Step 7 → Properties & Fields Step 8 → Constructors Step 9 → Methods & Overloading Step 10 → Null Handling PHASE 2 — C# Specific Features -------------------------------- Step 11 → Collections — List<T>, Dictionary<K,V>, IReadOnlyList<T> Step 12 → LINQ — .Where(), .Select(), .Sum(), .FirstOrDefault() Step 13 → Async / Await & Task Step 14 → Generics — Task<T>, IOptions<T>, List<T> Step 15 → Exception Handling PHASE 3 — ASP.NET Core ----------------------- Step 16 → Project Structure — .csproj, Program.cs, appsettings.json Step 17 → Dependency Injection (DI) Step 18 → Controllers & Routing — [HttpPost], [Route], [FromBody] Step 19 → Middleware & Pipeline Step 20 → Options Pattern — IOptions<T>, appsettings.json PHASE 4 — Advanced ------------------- Step 21 → Repository Pattern Step 22 → Records vs Classes Step 23 → Pattern Matching & Switch Expressions Step 24 → Attributes / Decorators Step 25 → CancellationToken & Async Patterns
Step 1 — Keywords & Identifiers
Before writing any C# code, you need to know two fundamental things: what names you are allowed to give things (identifiers) and what words the language already owns (keywords).
Good news — if you know JavaScript, you already understand the idea. We just need to learn the C# flavour.
What is an Identifier?
An identifier is simply a name you give to something — a class, a method, a variable, a parameter. It is the same concept in both JS and C#.
// JavaScript
const myVariable = 10;
function myFunction() {}
class MyClass {}
// C#
int myVariable = 10;
void MyMethod() {}
class MyClass {}
The logic is the same. But C# has a strict naming convention that the whole ecosystem follows:
C# Naming Convention
=====================
PascalCase → Classes, Methods, Properties, Interfaces
Example: RecommendationEngine, BuildDeterministicAsync
camelCase → Local variables, method parameters
Example: catalogPlan, effectiveTaxRate
_camelCase → Private fields (underscore prefix)
Example: _catalogRepository, _options, _rules
IPascalCase → Interfaces always start with "I"
Example: IRecommendationEngine, IPlanCatalogRepository
Compare with JavaScript:
========================
JS has no enforced convention — you can name things however you like.
C# has a community-wide standard — everyone follows the same rules.
In the real project file RecommendationEngine.cs, you can see all three naming styles in action:
public sealed class RecommendationEngine : IRecommendationEngine
// ↑ PascalCase class ↑ PascalCase interface (starts with I)
{
private readonly IPlanCatalogRepository _catalogRepository;
// ↑ _camelCase private field
public async Task<DeterministicWithFacts> BuildDeterministicAsync(
// ↑ PascalCase method name
EmployeeContextRequest request,
// ↑ camelCase parameter
CancellationToken cancellationToken)
// ↑ camelCase parameter
{
var catalog = await _catalogRepository.GetCatalogAsync(cancellationToken);
// ↑ camelCase local variable
}
}
What are Keywords?
Keywords are words reserved by the language. You cannot use them as identifiers. C# has around 80 reserved keywords. You don't need to memorise all of them — here are the ones you will see constantly in this project:
Core Keywords You Will See in This Project ========================================== Keyword │ What it does │ JS Equivalent ────────────┼───────────────────────────────────────┼────────────────────────────── namespace │ Groups related classes (like a folder)│ (like a module path / folder) using │ Imports a namespace │ import class │ Defines a class │ class interface │ Defines a contract (shape) │ TypeScript interface var │ Infers the type automatically │ const / let return │ Returns a value from a method │ return new │ Creates a new object instance │ new static │ Belongs to the class, not an instance │ static (JS class) private │ Only usable inside this class │ # (private field in modern JS) public │ Usable from anywhere │ (exported, no keyword needed) sealed │ Cannot be subclassed (no extends) │ Object.freeze (concept only) async │ Marks a method as asynchronous │ async await │ Waits for an async result │ await null │ Represents no value │ null void │ Method returns nothing │ (implicit in JS functions) readonly │ Value can only be set in constructor │ const (closest concept) required │ Property must be set when created │ required field (TypeScript) override │ Replaces a parent class method │ (overriding in JS class) true/false │ Boolean values │ true / false this │ Refers to the current instance │ this foreach │ Loop over a collection │ for...of if/else │ Conditional logic │ if / else
Real Project Example — Reading the Top of RecommendationEngine.cs
Let's read the first 6 lines of the real project file and decode every keyword:
// File: BenefitRecommendations.Api/Services/RecommendationEngine.cs using BenefitRecommendations.Api.Models; // keyword: using using BenefitRecommendations.Api.Options; // keyword: using using BenefitRecommendations.Api.Repositories; // keyword: using using Microsoft.Extensions.Options; // keyword: using namespace BenefitRecommendations.Api.Services; // keyword: namespace public sealed class RecommendationEngine : IRecommendationEngine // ↑ ↑ ↑ ↑ // public sealed class : means "implements"
Breaking it down line by line:
Line-by-Line Breakdown
=======================
using BenefitRecommendations.Api.Models;
─────────────────────────────────────────
"using" = import
JS equivalent: import { ... } from './models'
It gives this file access to all classes inside the Models folder.
namespace BenefitRecommendations.Api.Services;
───────────────────────────────────────────────
This file's "address" in the project.
JS equivalent: like the file path — src/services/RecommendationEngine.js
Other files use this address to import things from here.
public sealed class RecommendationEngine : IRecommendationEngine
─────────────────────────────────────────────────────────────────
public → Anyone can use this class from outside
sealed → No other class can inherit/extend this class
class → It is a class (same as JS class)
: IRecommendationEngine → Implements the IRecommendationEngine interface
(like TypeScript: class X implements IY)
JavaScript vs C# — Side by Side
JAVASCRIPT C# EQUIVALENT
──────────────────────────────────────────────────────────────────────
import { Models } from './models' using BenefitRecommendations.Api.Models;
// No namespace concept in JS namespace BenefitRecommendations.Api.Services;
class RecommendationEngine public sealed class RecommendationEngine
#catalogRepository private readonly IPlanCatalogRepository _catalogRepository;
constructor(repo) { public RecommendationEngine(IPlanCatalogRepository repo) {
this.#catalogRepository = repo; _catalogRepository = repo;
} }
async buildDeterministic(req) { public async Task<DeterministicWithFacts>
const catalog = BuildDeterministicAsync(EmployeeContextRequest request,
await this.#catalogRepository CancellationToken cancellationToken) {
.getCatalog(); var catalog =
return this.#build(req, catalog); await _catalogRepository.GetCatalogAsync(cancellationToken);
} return BuildDeterministic(request, catalog);
}
The logic is identical. The only difference is that C# is more explicit — you declare types, access modifiers, and return types everywhere. JavaScript lets you skip all of that.
The Biggest Difference — C# is Statically Typed
In JavaScript you write:
let x = 10; // JS figures out the type at runtime let y = "hello"; // no type declaration needed
In C# you must tell the compiler the type upfront:
int x = 10; // must say: this is an integer string y = "hello"; // must say: this is a string
But C# also has var — so you can skip writing the type when it is obvious:
var x = 10; // C# compiler sees 10 → knows it's an int var y = "hello"; // C# compiler sees "hello" → knows it's a string // This is like TypeScript's type inference! // var in C# ≠ var in JS // C# var is always a fixed type — it just lets the compiler figure it out. // After var x = 10, you CANNOT do x = "hello" — the type is locked as int.
You will see var used constantly in this project for local variables (e.g., var catalog, var result, var employerId).
Summary
What you learned in Step 1 =========================== Identifiers ─────────── → Names you give to classes, methods, variables → PascalCase for classes/methods/properties → camelCase for local variables and parameters → _camelCase for private fields → IPrefix for interfaces Keywords (most important ones) ─────────────────────────────── → using = import → namespace = module address / folder path → class = class → public = accessible from outside → private = only inside this class → sealed = cannot be extended → var = type inference (like TS inference, not JS var) → async = async function → await = await → void = no return value → readonly = can only be set once (in constructor) Big Difference from JS ─────────────────────── → C# is statically typed — every variable has a fixed type → You declare types explicitly (or use var and let the compiler infer) → Once a type is set, it cannot change
What's Next?
In Step 2 — Data Types & Variables, we will go deep into all the types C# gives you: string, int, decimal, bool, DateOnly, List, Dictionary and more — and see exactly where each one is used in this project.
Stay tuned!
Post a Comment