C# vs JavaScript

C# vs JavaScript: C# vs JavaScript: an overview, Static vs Dynamic Typing, Working with Functions, Arrays, Arrow Functions, Summary.

Updated

  1. C# vs JavaScript: an overview (Novice): JavaScript was made for browsers in 1995 and is standardized as ECMAScript. It looks like C#, with braces, if and for, but it's a different language. It runs in every browser, and in Node.js outside one.
  2. Static vs Dynamic Typing (Novice): In C#, a variable's type is fixed when it's declared. In JavaScript, variables have no type; values do, and a variable can hold any of them. Declare with const by default, let when the value changes, and never var.
  3. Working with Functions (Apprentice): A JavaScript function is declared with the function keyword, and has no return type and no parameter types. A missing argument is undefined, an extra one is ignored, and a function with no return gives undefined. Functions are values, too.
  4. Arrays (Apprentice): A JavaScript array works like a C# List<T>. It grows and shrinks with push, pop, shift and unshift, and has length, includes and indexOf. Its filter, map, find and reduce methods do the jobs of LINQ's Where, Select, First and Sum.
  5. Arrow Functions (Apprentice): An arrow function is JavaScript's lambda, written (a, b) => a + b, almost exactly like C#. One parameter needs no parentheses, a body in braces needs a return, and an object returned on its own needs parentheses around it.
  6. Summary (Apprentice): Compare with === and !==, never == and !=, which convert types first. In a condition, false, 0, an empty string, null, undefined and NaN count as false, and everything else as true. A cheat sheet of C# and its JavaScript equivalents.