-
JavaScript is a lightweight compiled programming language with the first-class functions.
-
JavaScript was created to run in the browser (mostly used for the Web), however it is also used in non-browser environments: Node.js (server side) and Electron (desktop applications).
-
ECMAScript is the standard for JavaScript and its implementation.
-
The most recent versions of ECMAScript (shorter ES) that are currently being used are :
ES5 (from 2009.), ES6 (from 2015.), ES7 (2016.)
-
JavaScript never removes old features – new versions are always backward compatible, meaning that new versions of the language include old features and new features can be converted to the legacy code.
- Parentheses () and curly braces {} are mandatory and will cause an error if they’re left out, with few exceptions.
- JavaScript does not strictly require semicolons
;
, however we use them always to prevent possible errors.
-
Variable is a named container or a storage for data in the memory.
-
Variable can be declared with keyword
var
orlet
orconst
. -
Different values (known as data types) can be stored in variables : string, *number, array, object, function, boolean, etc.
// Objects
var myArray = [];
var myObject = {};
// Primitives
var myString = "Uros";
var myNumber = 100;
var myBoolean = true; // true or false
var myNull = null;
var myUndefined = undefined;
// We won't use the below data types
var mySymbol = Symbol();
var myBigInt = 9007199254740991n;
- Declaring simply means “saving a spot in a memory” without assigning any value to it.
var a;
- Assigning means storing the value in a variable, using the
=
operator.
a = 10;
- We can declare a variable and assign the value on the same line.
var user = 'Sarah';
-
In JS variable names can contain letters (uppercase and lowercase), numbers and the symbols
_
and$
. -
In JS the first character of the variable name cannot be a number.
-
Write variable names that are easily understandable and human readable. Don't one letter names, you are better than that :) !
-
Name variables as descriptive and concise as possible (examples of good naming: userName, creditCardNo, and examples of bad names:
info
,value
, etc.) -
camelCase notation is the common convention when naming variables.
-
As a common style guide during the bootcamp we will be using single quotes in Javascript
''
. -
When writing code use 2 spaces indentation (set 2 spaces indentation in your editor ).
- Keywords are tokens that have special meaning in JavaScript and cannot be used as variable names. Most common ones are:
var
,function
,return
,let
,const
,typeof
,new
,for
, etc. ...
- JavaScript is a dynamically typed language which means that new variables can be created during the runtime, and the type of variables is determined at runtime.
- Simply put variables can be reassigned different value of a different types at runtime.
🔖 typeof
is JavaScript operator that returns the type of the variable we passed to it. You can read more about it here.
var myVar = "IronHack";
console.log(typeof myVar);
myVar = 100; // We reassing a new value of a different type to myVar
console.log(typeof myVar);