Getting Started:
- Text in Javascript ALWAYS needs to have to be grab in quotes
Variables & String
- by default, variables have the value "undefined", meaning is empty
- we can declare and assign variables at the same time
- camel-cased: first letter is lowercase, but next word is uppercase (by convention). For example: firstName
- Requirements: 1) name just letter, number, "$", and "_" 2) first character must not be a number, 3) cannot use reserved name (like "var")
- Browser: window // Server: global
- Sloppy (normal) mode: default // Strict mode: throws more errors, but prevents better ->
"use strict";
But this does not solve all the problems -
let
&const
to declare variables, but let can be reassigned (likevar
). Use cont unless it will be reassigned - Variable shadowing: let & const are block-scoped
- Template literal for string interpolation: to add variables in strings
Hi ${username}
(we can do operations or put conditions inside the {} ). It use ` not ' - Variables names are case sensitive
- Variables names should be descriptive and in camel-cased. Any variable can be of any type, that is why is so important to follow this convention, so others know what we are doing
- Other conventions:
isSomething
orhasSomething
to do condicional, for constant we use all caps and _ to separate (FIRST_NUMBER)
Top comments (0)