Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Introduction To JavaScript

Uploaded by

TiNiK Esports
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Introduction To JavaScript

Uploaded by

TiNiK Esports
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

JAVA SCRIPT 7 DATA TYPES:~~~~~

undefined = a variable that hasn't been defined


null = a something that is nothing
boolean = for true or false
string = for texts
symbol = an immutable primitive value that is unique
number = for numbers
object = can store a lot of different key calue pairs.

var = is used throught the whole program


let = is used within the scope of where you declared that
const = a variable should never change

STORING VALUABLES WITH ASSIGNMENT OPERATOR~~~~~~~~~

console.log(?) = allows you to see things in the console


? = for the varname

CASE SENSITIVITY IN
VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

varnames starts with small letter and next words starts with uppercase

INCREMENTING / DECREMENTING
NUMBERS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

instead of eg. myVar = myVar + 1;


use myVar++ because ++ is equals to increment value by 1
for decrementing use --

ADD/MULTIPLY/SUBTRACT/DIVIDE varnames and


signs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sum + difference + product + quotient +

FINDING
REMAINDERS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var remainder = 11 % 3; in console is 2 becuase 11 % 3 is divide


this is used to determine whether the number is odd or even

COMPOUND ASSIGNMENT WITH AUGEMENTED


ADDITION/SUBT/MULT/DIV~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var a = 3;
instead of using a = a + 9, use a += 9; for a shortcut
so,
add +=
sub -=
mult *=
div /=

DECLARE STRING
VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if something is surrounded by "", '', ``, they are strings


var firstName = "Niko Andrei"; inside the texts alongside the symbol are called
string laterals

ESCAPING LATERAL
STRINGS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var myStr = "I am a \"double quoted\" string inside \"double quotes\"";

in order for the string to count as one you should add a backslash(\) to connect
the strings

ESCAPING DOUBLE QUOTES WITH SINGLE STRINGS LIKE HTTP


URLs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var myStr = 'I am a "double quoted" string inside "double quotes"';

use a single quote at the beginning and at the end of the string so you can
eliminate tha backslashes before double quotes
or you can use backticks (``)

ESCAPE
SEQUENCES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code Outputs:
\' single quote
\" double quote
\\ backslash
\n newline
\r carriage return
\t tab
\b backspace
\f form feed

eg.

var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";

CONCATENATING STRINGS WITH PLUS


OPERATOR~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var ourStr = "I come first. " + "I come second; or

var myStr = "I come first"


myStr += "I come second";

CONSTRUCTING STRINGS WITH


VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var myFullName = "Niko Andrei Pepito";


var myStr = "Hi my name is " + myFullName +" and I'm feeling good";
console.log(myStr);

RESULT: Hi my name is Niko Andrei Pepito and I'm feeling good


APPENDING VARIABLE TO STRINGS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var someAdjective = "Interesting";


var myStr = "Learning code is "
myStr += someAdjective;
console.log(myStr);

RESULT: Learning code is Interesting

FINDING STRING LENGTH~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var firstNameLength = 0;
var firstName = "Niko";

firstNameLength = firstName.length
console.log(firstNameLength);

RESULT: 4

BRACKET NOTATION~~~~~~~~~~~~~~~~~

var firstLetterOfLastName = "";


var lastName = "Pepito";

firstLetterOfLastName = lastName[0]
console.log(firstLetterOfLastName);

inside the bracket indicates the exact element according to the number
first element always start with 0

STRING IMMUTABILITY~~~~~~~~~~~~~~

var myStr = "Jello World";


my Str[0] = "H"; this will give you an error because it cannot be change but
instead, use

var myStr = "Jello World";


myStr = "Hello World";

FINDING LAST LETTER OF STRING~~~~~~~~~~~

var firstLetterOfLastName = "";


var lastName = "Pepito";

firstLetterOfLastName = lastName[lastName.length - 1]
console.log(firstLetterOfLastName);

RESULT: o

WORDBLANKS~~~~~~~~~~~~~~~

function wordBlanks(myAdjective, myNoun, myVerb) {


var result = "";
result += myNoun + " is very " + myAdjective + " in " + myVerb + " coding.";

return result;
}
console.log(wordBlanks("brilliant", "Niko Andrei", "performing"));
console.log(wordBlanks("smart", "Blaise", "performing"));

RESULT: Niko Andrei is very brilliant in performing coding.


RESULT: Blaise is very smart in performing coding.

ARRAYYS~~~~~~~~~~~~~~~

arrays can be use to store multiple data eg.


inside the brackets you can add the CODE OUTPUTS (found above)
var myArray = ["Niko", 17]

NESTED ARRAY~~~~~~~~~
var myArray = [["Niko", 17], ["Blaise",17]]

ACCESS ARRAY DATA~~~~~~~~~~~~~~~


var myArray = [17,18,19];
var myData = myArray[0]
console.log(myData)

RESULT: 17

ARRAYS ARE NOT IMMMUTABLE UNLIKE STRINGS~~~~~~~~

var myArray = [17,18,19];


myArray[2] = 23
console.log(myArray)

RESULT: [17,18,23]

MULTIDIMENSIONAL ARRAY~~~~~

var myArray = [[17,18,19], [20,21,22], [23,24,25], [[26,27,28],29,30]];


myData = myArray[3][0];
console.log(myData)

RESULT: [26,27,28]

PUSH()

var myArray = [["Niko", 17], ["Blaise",17]]


myArray.push(["Chan", 23])
console.log(myArray)

RESULT: [ [ 'Niko', 17 ], [ 'Blaise', 17 ], [ 'Chan', 23 ] ]

You might also like