Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3n-e4b-it· GoogleHugging Face LMArena Human Preference 140K

JavaScript programming language cheat sheet.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-v3-0324’s answer.
  1. User

    JavaScript programming language cheat sheet.

  2. Google Assistant

    JavaScript Cheat Sheet - A Comprehensive Guide

    This cheat sheet covers essential JavaScript concepts, syntax, and common functions. It's organized for quick reference.

    I. Basic Syntax & Data Types

    • Comments:

      • // Single-line comment
      • /* Multi-line comment */
    • Variables:

      • var (older, function-scoped)
      • let (block-scoped, can be reassigned)
      • const (block-scoped, cannot be reassigned)
      • let x = 10;
      • const PI = 3.14159;
    • Data Types:

      • Primitive:
        • Number: 10, 3.14, -5
        • String: "Hello", 'World'
        • Boolean: true, false
        • Null: null (represents intentional absence of a value)
        • Undefined: undefined (variable declared but not assigned a value)
        • Symbol: Symbol('description') (unique and immutable identifier)
        • BigInt: 123456789012345678901234567890n (for integers larger than Number can represent)
      • Object:
        • Object: { name: "John", age: 30 }
        • Array: [1, 2, 3]
    • Operators:

      • Arithmetic: +, -, *, /, % (modulo), ** (exponentiation)
      • Assignment: =, +=, -=, *=, /=, %=
      • Comparison: == (loose equality), === (strict equality), != (loose inequality), !== (strict inequality), >, <, >=, <=
      • Logical: && (AND), || (OR), ! (NOT)
      • Ternary: condition ? valueIfTrue : valueIfFalse

    II. Control Flow

    • if...else Statements:

      if (condition) {
        // Code to execute if condition is true
      } else if (anotherCondition) {
        // Code to execute if anotherCondition is true
      } else {
        // Code to execute if all conditions are false
      }
      
    • switch Statement:

      switch (expression) {
        case value1:
          // Code to execute if expression equals value1
          break;
        case value2:
          // Code to execute if expression equals value2
          break;
        default:
          // Code to execute if expression doesn't match any case
      }
      
    • for Loop:

      for (initialization; condition; increment/decrement) {
        // Code to execute repeatedly
      }
      
    • while Loop:

      while (condition) {
        // Code to execute repeatedly as long as condition is true
      }
      
    • do...while Loop:

      do {
        // Code to execute at least once
      } while (condition);
      
    • for...in Loop: (Iterates over object properties)

      for (let key in object) {
        // Code to execute for each property key
      }
      
    • for...of Loop: (Iterates over iterable objects like arrays, strings, Maps, Sets)

      for (let value of iterable) {
        // Code to execute for each value
      }
      

    III. Functions

    • Function Declaration:

      function functionName(parameters) {
        // Code to execute
        return value; // Optional return statement
      }
      
    • Function Expression:

      const functionName = function(parameters) {
        // Code to execute
        return value;
      };
      
    • Arrow Function (ES6+):

      const functionName = (parameters) => {
        // Code to execute
        return value;
      };
      
      // Single expression - implicit return
      const functionName = (parameters) => value;
      
    • Parameters & Arguments:

      • parameters are defined in the function declaration.
      • arguments (in older functions) is an array-like object containing all arguments passed to the function. (Less common with arrow functions)
    • return Statement: Exits the function and optionally returns a value.

    • Function Scope: var has function scope, let and const have block scope.

    • Higher-Order Functions: Functions that can take other functions as arguments or return functions. Examples: map, filter, reduce.

    IV. Objects

    • Object Literals:

      const person = {
        name: "Alice",
        age: 25,
        city: "New York",
        greet: function() {
          console.log("Hello, my name is " + this.name);
        }
      };
      
    • Accessing Properties:

      • object.property (dot notation)
      • object["property"] (bracket notation - useful for dynamic property names)
    • Adding/Modifying Properties:

      • object.newProperty = value;
      • object.property = newValue;
    • Deleting Properties:

      • delete object.property;
    • this Keyword: Refers to the object that the function is being called on. Its value depends on how the function is called.

    • Object Methods: Functions that are properties of an object.

    • Constructor Functions: Used to create objects using the new keyword.

    • Classes (ES6+): A syntactical sugar over prototype-based inheritance.

      class Person {
        constructor(name, age) {
          this.name = name;
          this.age = age;
        }
      
        greet() {
          console.log("Hello, my name is " + this.name);
        }
      }
      
      const person = new Person("Bob", 40);
      person.greet();
      

    V. Arrays

    • Array Literals:

      const myArray = [1, 2, 3, "hello", true];
      
    • Accessing Elements:

      • array[index] (zero-based indexing)
    • Array Methods:

      • push(element): Adds an element to the end of the array.
      • pop(): Removes the last element from the array.
      • shift(): Removes the first element from the array.
      • unshift(element): Adds an element to the beginning of the array.
      • splice(startIndex, deleteCount, item1, item2, ...): Modifies the array by removing or replacing elements.
      • slice(startIndex, endIndex): Returns a new array containing a portion of the original array.
      • concat(array1, array2, ...): Returns a new array by concatenating the original array with the other arrays.
      • join(separator): Converts the array to a string.
      • indexOf(element): Returns the index of the first occurrence of an element.
      • includes(element): Returns true if the array contains the element.
      • forEach(callbackFunction): Executes a provided function once for each array element.
      • map(callbackFunction): Creates a new array with the results of calling a provided function on every element in the calling array.
      • filter(callbackFunction): Creates a new array with all elements that pass the test implemented by the provided function.
      • reduce(callbackFunction, initialValue): Reduces the array to a single value.
      • sort(compareFunction): Sorts the array elements.
      • reverse(): Reverses the order of the array elements.

    VI. DOM Manipulation

    • document Object: Represents the HTML document.

    • Selecting Elements:

      • document.getElementById(id): Gets an element by its ID.
      • document.getElementsByClassName(className): Gets elements by their class name (returns an HTMLCollection).
      • document.getElementsByTagName(tagName): Gets elements by

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.