Syntax, Types, Expressions and Statements.
var lessonPart = [{
theme: 'JavaScript Syntax',
target: 'Learn it somehow'
}];
Charset
Unicode
eval(z='p="<"+"pre>"/* ###########* */;for(y in n="zw24l6k\
4e3t4jnt4qj24xh2 x/* ############ */42kty24wrt413n243n\
9h243pdxt41csb yz/*##############* ## */43iyb6k43pk7243nm\
r24".split(4)){/* ########* *## */for(a in t=pars\
eInt(n[y],36)+/*##########* ##### */(e=x=r=[]))for\
(r=!r,i=0;t[a/* ##########* *##### */]>i;i+=.05)wi\
th(Math)x-= /* *##########* ### # */.05,0<cos(o=\
new Date/1e3/* *#####* ###### */-x/PI)&&(e[~\
~(32*sin(o)*/* ###* ########## */sin(.5+y/7))\
+60] =-~ r);/* ####* *########## */for(x=0;122>\
x;)p+=" *#"/* ######### *##### */[e[x++]+e[x++\
]]||(S=("eval"/* ############* ## */+"(z=\'"+z.spl\
it(B = "\\\\")./* *####### ## */join(B+B).split\
(Q="\'").join(B+Q/* *#####* *# */)+Q+")//m1k")[x/2\
+61*y-1]).fontcolor/* *## # */(/\\w/.test(S)&&"#\
03B");document.body.innerHTML=p+=B+"\\n"}setTimeout(z)')//m1k\
(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])
[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+
[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[
]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(
!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!
+[]+!+[]+[+[]]]+[+!+[]]+(!![]+[][(![]+[])[+[]
]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!
+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]
+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]] // ()+[]!
Зв
езда
<bOdY
oNLOAd=
"Я=[];Л=
{};Ж=!Я;З=
!Ж;Ч=!+Я;Д=
Ч+Ч;П=З+Я;Б=Д+Ч;Ю=Ж+Я;Ф=[Ж]+Я[Я];И=П[+Ч]
Ы=Я[Ю[+Я]+Ф[+Ч+[+Я]]+Ю[Д]+П[+Я]+П[
Б]+И];C=Я[Я]+Я;P=Я+Л;Ь=Д+Б;Ш
=+Ч;X=+Я;Й='★';К='Й'
H=П[X];T=Д+[X];Ы[P
[Ь]+P[Ш]+C[Ш]+Ю[Б]+H
+И+C[X]+P[Ь]+H+P[Ш]+И
](Ю[Ш]+Ю[ Д]+П[Б]+И
+H+(Ж+Ы )[T]+К+
(З+Ы) [T])(
)"> смЕ
р Ти
Text
Text
http://aem1k.com/
- Case sensetive, whitespaces and line brakes are ommited
- \u0020, \u0009, \u000B, \u000C, \u00A0 - Whitespaces
- \u000A, \u000D, \u2028, \u2029 - Line Brakes
- \u200F, \u200E - Format control characters
- Hasn't normalization
- Must begins from (_), any letter of $ sign
- Subsequent digits are allowed, but not starting!
- Prefer camelCase
Text
Identifiers
Keywords:
break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with
Reserved Words:
class, const, enum, export, extends, import, super
Strict Mode Reserved Words:
implements, interface, let, package, private, protected, public, static, yield
Not allowed as variable, function, or parameter names:
arguments, eval
Text
Reserved Words
Optional Semicolon
...
NO!
Comments
// This is a single-line comment.
/* This is also a comment */ // and here is another comment.
/*
* This is yet another comment.
* It has multiple lines.
*/
/**
* Documentation comments
* Treats by plugins such as @JSDoc for creating documentations
*/
Literals
12 // Number twelve
1.2 // Number one point two
"hello world" // String of text
'Hi' // One more string
true // Boolean
false // Falsy boolean
/javascript/gi // Regexp
null // No object
{ x:1, y:2 } // An object initializer
[1,2,3,4,5] // An array initializer
Data Types
Primitives
- number
- string
- boolean
- null
- undefined
Objects
All rest what is Objects in JS
Such as:
- Object
- Array
- Function
Numbers
- IEEE 754
- 64-bit
- −9007199254740992 (−2^53 )
- 9007199254740992 (2^53 )
- Math class similar to Javas One
- [digits][.digits][(E|e)[(+|-)]digits]
- can be integer or float
Special Constants
Infinity
Number.POSITIVE_INFINITY
1/0
Number.MAX_VALUE + 1
Number.NEGATIVE_INFINITY
-Infinity
-1/0
-Number.MAX_VALUE - 1
NaN
Number.NaN
0/0
Number.MIN_VALUE/2
-Number.MIN_VALUE/2
-1/Infinity
-0
string
"" // The empty string: it has zero characters
'testing'
"3.14"
'name="myform"'
"Wouldn't you prefer O'Reilly's book?"
"This string\nhas two lines"
"π is the ratio of a circle's circumference to its diameter"
"two\nlines" // A string representing 2 lines written on one line
"one\ // A one-line string written on 3 lines. ECMAScript 5 only.
long\
line"
<button onclick="alert('Thank you')">Click Me</button>
String
msg = "Hello, " + "world"; // Produces the string "Hello, world"
greeting = "Welcome to my blog," + " " + name;
s.length // Special property
var s = "hello, world"
s.charAt(0)
s.charAt(s.length-1)
s.substring(1,4)
s.substr(1,4)
s.slice(1,4)
s.slice(-3)
s.indexOf("l")
s.lastIndexOf("l")
s.indexOf("l", 3)
s.split(", ")
s.replace("h", "H")
s.toUpperCase()
//ES-5 Only Features, strings behave like arrays
s = "hello, world";
s[0] // => "h"
s[s.length-1] // => "d"
More on String
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Methods
boolean
true
false
- undefined
- null
- 0
- -0
- NaN
- "" // the empty string
All other values, object and arrays.
- Evaluates from logic and comparison operations
- Used in control flow statements
null and undefined
- Represents absence of value.
- null for objects
- undefined for variables which is not yet initialized
- undefined for object properties which is not exists
- undefined for functions arguments which is not supplied
- Both can be assigned as values
- Sole members of its own types
- Functions without return, in a fact returns undefined
- undefined for unexpected error-kind behavior
- null for expected error-kind behavior
- null == undefined // true
- null === undefined // false
Globals and Wrappers
- properties like undefined , Infinity , and NaN
- functions like isNaN() , parseInt(), and eval()
- constructor functions like Date() , RegExp() , String() , Object(), and Array()
- objects like Math and JSON
var s = 'test', n = 1, b = true;
var string = new String(s);
var number = new Number(n);
var boolean = new Boolean(b);
Type Conversion
Type Conversion
o.valueOf()
o.toString()
"=="
"==="
Type Conversion
TypeError
Expressions and Statements
Variables
- var keyword for locals, or globals
- no var keywords for globals (bad stuff)
- function scope
- hoisted
var
let
- block scoped
- has temporal dead zone
Variable Hoisting
var scope = "global";
function f() {
console.log(scope);
var scope = "local";
console.log(scope);
}
Operators
In Comparison with Java
- function
- typeof
- in
- for in
- void
- no shorthand logical operators
Expressions
- Declarations,
- In-line Expressions
- Loops
- Conditions
- Jumps (GoTos)
Declarations
var someVariable = 'content'; // Declared and initialized
var someVar1; // Only declared
let scopedVar = 123; // Scoped var declaration
globalStuff = 'nuff said'; // Bad stuff actually...
function foo() { // Function declaration
var local = 'local';
if (local === 'local') {
let scoped = 'scoped';// Where its really useful
}
}
var bar = function() { // Function expression
return 'bar'
};
Expressions
function someFunc(x) {
console.log('x is ' + x);
}
console.log(someFunc(1) === undefined);
{
x = 2;
x *= x;
console.log('x * x = 'x);
}
for(i = 0; i < a.length; a[i++] = 0) ;
Conditions
if(isTruthy) {
doStuff();
}
if(isTruthy) {
doStuff();
} else {
doOtherStuff();
}
if(isTruthy) {
doStuff();
} else if(someMoreTruth) {
doSomeAnotherStuff()
} else if(universeQuestion) {
doNirvana();
} else {
doFrustrating();
}
Conditions
switch(n) {
case 1:
// incredible code 1
break;
case 2:
// awesome code option 2
break;
case 3:
// great solution code 3
break;
default:
// trivial default code...
break;
}
Conditions
switch(n) {
case 1:
// case can be an expression rather than literal
// incredible code 1
break;
// no efficient
case 2:
// awesome code option 2
break;
case 3:
// great solution code 3
break;
default:
// trivial default code...
break;
}
Loops
while(expr) {
//repeating stuff
}
do {
// repeating stuff which runs at least once
} while(expr)
for(expr1;expr2;expr3) {
// iterating
}
for(var prop in obj) {
console.log(prop + obj[prop]);
}
Jumps
label: statements;
break: label;
continue: label;
return expression;
throw someError;
try{
doStuff();
} catch(error) {
// brace yourselves Exceptions is coming!
retaliate();
} finally {
// do in almost any cases.
finalMove();
}
with(object)
statement;
debugger;
'use strict';
Questions?
See you next time =)
JS Training Lesson 2
By diodredd
JS Training Lesson 2
- 328