This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| FUNCTIONS: PROGRAMS WITHIN PROGRAMS! | |
| There are two phases to using functions. First we must declare (define) it. | |
| We declare a function and name it square. We could put parameters in paranthesis "()": | |
| */ | |
| function square(number) {} | |
| /* | |
| Now we can invoke/call/execute the function. It happens between curly brackets "{}". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| LOOPS: WHILE, FOR, FOR-IN | |
| While loops are less popular than for loops. | |
| They are more manual and work better with numbers. | |
| */ | |
| var count = 0; | |
| while (count < 11) { | |
| count++; // if you will miss this part, program will crash | |
| } // prints 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. It stopped at 11. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| CONTROL FLOW: IF, ELSE-IF, ELSE | |
| Conditionals are great to use with booleans. | |
| */ | |
| var a = 1; | |
| if(a > 0) { | |
| print('Yes'); | |
| } if (a === 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| STRING MANIPULATION | |
| The indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string. | |
| Search() works the same way: | |
| */ | |
| var str = 'Find where the string starts'; | |
| var res = str.indexOf('s'); | |
| console.log(res); // prints 15, it means first 's' is at 15th character |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*OPERATORS | |
| With special operators we could do many tasks, like assigning, comparing etc. | |
| ASSIGNMENT. Use the "=" sign to assign values to variables: | |
| */ | |
| x = 1; // value of 1 is assigned to x | |
| x += 1; // means x = x + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| DATA TYPES (Simple & Complex) | |
| JavaScript has built-in data types, which are called simple or complex. | |
| *Simple Data Types | |
| Simple data types are data types whose values cannot be changed. | |
| The simple data types are |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * VARIABLES: | |
| * | |
| * Variables essentially function as placeholders for data/values. They can hold the place of things as simple | |
| * as a number, a string (e.g. var name = "Jacques") or Boolean to Arrays, Objects, or other data-types. | |
| * Variables... vary. Or at least they can if you want. You can change the value of a variable from a number | |
| * to a number, a number to a function, an oject to a function, etc. | |
| *HOW TO CREATE A VARIABLE? |