You don't know JS: Up and Going
-
A program, often referred to as source code or just code, is a set of special instructions to tell the computer what tasks to perform.
-
In a computer language, a group of words, numbers, and operators that performs a specific task is a statement.
-
In JavaScript a statement may look like this
a = b * 4
. Here, a and b is called as variable and 4 is called as literal value. -
Statements are made up of one or more expressions. An expression is any reference to a variable or value, or a set of variable(s) and value(s) combined with operators.
Executing a program
-
An interpreter or a compiler is used to translate the code you write into commands a computer can understand.
-
It’s typically asserted that JavaScript is interpreted, because your JavaScript source code is processed each time it’s run. But that’s not entirely accurate. The JavaScript engine actually compiles the program on the fly and then immediately runs the compiled code.
-
In chrome developer tools (in console) pressing
<shift> + <enter>
will take you to the next line, using this you can write code of multiple lines in the developer console. -
You can use
prompt
to take the input from the user
Operators
- Assignment:
=
- Math
+, -, *, /
- Compound Assignment
+=, -=, *=, /=
- Object Property access
.
(dot) - Equality
==, ===, !=, !==
- Comparison
<, >, <=, >=
- Logical
&&, ||
JavaScript
-
Javascript has typed values, not typed variables.
-
typeof null
is an interesting case, because it returnnsobject
, when you’d expect it to return null. This is a long-standing bug in JS, but one that is likely never going to be fixed. Too much code on the Web relies on the bug and thus fixing it would cause a lot more bugs! -
The object type refers to a compound value where you can set properties (named locations) that each hold their own values of any type.
let obj = {
name: 'prajwal',
language: 'JS'
}
// you can acess the values of a
// property using dot notation
obj.name; // prajwal
obj.language; //JS
Array
: An array is an object that holds values (of any type) not particularly in named properties/keys, but rather in numerically indexed positions.