Skip to content

01. Data Types, Declaration, Operators

idavidov13 edited this page Nov 28, 2023 · 7 revisions

Data Types

Value - 2 different types

  • Object
  • Primitive

Primitive types

  • Number
  • String
  • Boolean
  • Undefined
  • Null
  • Symbol
  • BigInt

Type Conversion and Coercion(happens behind the scene - JS try to convert inputs in order to perform the operators)

  • Number("input")
  • String("input")

Declaration

var

let

const

Operators

Basic Operators

  • Mathematic operations - +, -, *, /
  • Assignment - +=, -=, *=, /=
  • Iteration - ++, --
  • Comparison - <, >, ===, ==, <=, >=, <>
  • Equality - ===(comparisson of the type and value) or ==(comparisson only for the value) / !==(strict version) or !=(loose version)
  • Concatenation - 'Ivan' + 'Davidov' = 'IvanDavidov'

Operators Precedence

MDN Operator Precedence Table

Boolean Logic Operators (AND (&&), OR (||), NOT (!))

The Conditional (Ternary) Operator

age >=18 ? console.log('Whiskey') : console.log('Water')

Logical Operators

String literals

I'm ${firstName}, a ${age} years old ${job}!

Decisions

if/else statements

if(condition) { } else { };

Truthy and Falsy Values

  • Falsy values - false, 0, '', undefined, null, NaN

Switch Statement

switch(input) { case 'caseOne': some code; break; case 'caseTwo': some code; break; case 'caseThree': some code; break; case 'caseFour': some code; break; default: some code; }

Statements and Expressions

Regular Expressions (RegExp)

What Are Regular Expressions?

  • Match text by pattern
  • Patterns are defined by special syntax, e.g.

[0-9]+ matches non-empty sequence of digits [A-Z][a-z]* matches a capital + small letters building RegExp

Predefined classes

  • \w – matches any word character (a-z, A-Z, 0-9, _)
  • \W – matches any non-word character (the opposite of \w)
  • \s – matches any white-space character
  • \S – matches any non-white-space character (opposite of \s)
  • \d – matches any decimal digit (0-9)
  • \D – matches any non-decimal character (the opposite of \d)

Quantifiers

    • – matches the previous element zero or more times
    • – matches the previous element one or more times
  • ? – matches the previous element zero or one time
  • {3} – matches the previous element exactly 3 times

Grouping Constructs

  • (subexpression) – captures the matched subexpression as a numbered group
  • (?:subexpression) – defines a non-capturing group
  • (?subexpression) – defines a named capturing group

Clone this wiki locally