File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ .idea
2+ node_modules
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > thenewboston</ title >
6+ </ head >
7+ < body >
8+ < script src ="main.js "> </ script >
9+ </ body >
10+ </ html >
Original file line number Diff line number Diff line change 1+
2+ /********** Scope **********/
3+
4+ // each function can only access its own scoped variables
5+ function one ( ) {
6+ var a = 5 ;
7+ console . log ( a ) ;
8+ }
9+
10+ function two ( ) {
11+ var a = 20 ;
12+ console . log ( a ) ;
13+ }
14+
15+ one ( ) ; // 5
16+ two ( ) ; // 20
17+
18+
19+ /********** Nested scope **********/
20+
21+ function outer ( ) {
22+ var a = 10 ;
23+
24+ // inner() has access to a since it is nested inside (part of) outer()
25+ function inner ( ) {
26+ var b = 27 ;
27+ console . log ( a + b ) ;
28+ }
29+
30+ inner ( ) ;
31+
32+ // can only access a
33+ console . log ( a ) ;
34+
35+ }
36+
37+ outer ( ) ;
Original file line number Diff line number Diff line change 1+
2+ /********** Objects **********/
3+
4+ // objects are composed of multiple names and values
5+ var person = {
6+ name : "Bucky" ,
7+ age : 87
8+ } ;
9+ console . log ( person . name ) ; // preferred
10+ console . log ( person [ 'age' ] ) ; // also valid
11+
12+
13+ /********** Arrays **********/
14+
15+ // array values are retrieved by index, not name
16+ var food = [ 'bacon' , 'tuna' , 'corn' ] ;
17+ console . log ( food [ 2 ] ) ;
18+
19+
20+ /********** Equality **********/
21+
22+ var a = '26' ;
23+ var b = 26 ;
24+
25+ console . log ( a == b ) ; // true (only checks value)
26+ console . log ( a === b ) ; // false (compares type as well)
Original file line number Diff line number Diff line change 1+ # JavaScript Lessons
Original file line number Diff line number Diff line change 1+ var isValid = false ;
2+
3+ function validParentheses ( arr ) {
4+ if ( arr [ 0 ] == '(' && arr [ arr . length - 1 ] == ')' ) {
5+ if ( arr . length == 2 )
6+ isValid = true ;
7+ else
8+ validParentheses ( arr . slice ( 1 , arr . length - 1 ) ) ;
9+ }
10+ return isValid ;
11+ }
12+
13+ console . log ( validParentheses ( '((()))' . split ( '' ) ) ) ;
You can’t perform that action at this time.
0 commit comments