Learn javaScript Basics- Day 4
- HTML: html used for describing content
- CSS: css used for describing presentation of the content
- JavaScript: javascript used for describing behaviours
- node filename.js
- click run button in VS code
- create a launch.json file
- select node.js preview
Programming is a set of instruction (which is written by programmer) that telling a computer what to do.
What does the alert() function do?
- The alert function opens up a pop-up box with whatever text you pass to it.
- The prompt function opens up a pop up box with a text field that allows the user to type an answer, which it will then return to code.
- Numbers
- String
- booleans
- null
- undefined
- object
- function
- Numbers: JavaScript only has one type for numbers: 64 bit floating point values. It includes two additional values: infinity and NaN (not a number)
- String: Strings are used to represent text in JavaScript. To create a string in JavaScript, you enclose characters with either single or double quote.
- Booleans: Booleans data types have two values: true and false.
- Object: In JavaScript, objects are king. If you understand objects, you understand JavaScript -w3schools.
- null: null is a primitive values and is treated as falsy for boolean operations.
- undefined: undefined means a variable declared, but no value has been assigned
- function
typeof is a built in function that help us to see the data type of any value.
- typeof(15)
- typeof "fruits"
- typeof prompt
- typeof 20/"fruits"
Numbers, string, boolean, null, object, function, undefined2. What is the difference between null and undefined?
undefined means a variable declared, but no value has been assigned. null is a primitive values and is treated as falsy for boolean operations.
3. Enter an expression in the console that evaluates to NaN.
parseInt("Hello");
Numbers, Arithmetic Operators, Comparators
Numbers: number is one type of data type in javascript. number needs to perform arithmetic operations.
Arthmectic Operators: Arithmetic operators are things like: +, -, *, and /. They're used to compute values. There are five arithmetic operators in JavaScript,
- +
- -
- *
- /
- %
- > (greater than)
- < (less than)
- ==
- ===
- !=
- !==
- >= greater or equal
- <= less or equal
if a = 35%10, then a is store 5 which which is the remainder after dividing 35 by 10.
PEMDES - parenthesis(bracket), exponent(3**4 = 81), Multiplication, Division, Addition, Subtraction
String
String is collection of charecter that is used to reperesent a text. Use "" to enclose the text. Example: myName="Mojnu"
Length Property
var charecterCount = "90 Day Challenge for Get a Job";String Concatenation
- String concatenation is combining two or more strings into a single string. For example:
var stringPlusNumber = 90 + " Day";console.log(stringPlusNumber)
3. Escape charecter?
- \t tab
- \n new line
- \r carriage return
- \' start /end of string
- \\ backslash
- \uHHHH
- A variable is a named reference to a location in memory for storing data.
- javascript is untyped, it means that you don't need to declare it's type.
- to create a variable you can simply type => var varName = value;
- variable name can not begin with number. Ex: 90day is not correct to declare a variable
- can not use special charecter in variable name without $ and -
- can not have space in variable name
- follow camel case when you declare a variable
var daysRemain = 86;
2. Find the length?
var quote = "My name is Mojnu. I am a full stack web developer. I challenge myself in september 1 to get a job in 90 day" console.log(quote.length);
3. Give an Example of Increment or decrement?
var days = 90; days++;
Conditional Statements
var days= 4;
if(days == 90) {
console.log("The End Game");
}
else if(days == 0) {
console.log("The Game Start");
}
else {
console.log("It's day 4, try hard mama");
}
- if("hello") - true condition
- if("") - false condition
- if(false) - falsy
- if(0) - falsy
- if(null) - falsy
- if(undefined) - falsy
- if(NaN) - falsy
- Loops can execute a block of code a number of times until complete the process
console.log(i);
}
//output: 1 2 3 4 5 6 7 8 9 10
While Loop:
console.log(days);
days--;
}
//output: 10 9 8 7 6 5
- JavaScript arrays are used to store multiple values in a single variable. -w3Schools
- const cars = ["Saab", "Volvo", "BMW"]; //declare an Array
- To access the items of an array, an indexer must be used: console.log(cars[2]) //result: BMW
- modify the tems in an array like this: cars[2] = "Toyota";
console.log(flowers.indexOf("lily"));
//result: 1
console.log(flowers.indexOf("bely"));
//result: -1 because bely flower is not in flowers array.
- indexOf return -1 if the items not found in the array
- lastIndexOf searches the item from the last in the array. Ex: lastIndexOf("tulip"); //output: 0
- remove item from to the end of array
- example: https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/pop.js
- add new item to the end
- example: https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/push.js
- remove first item from array
- Example: https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/shift.js
- add item to the first index of the array
- https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/unshift.js
- slice return the new array which is a part of an existing array
- https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/slice.js
- splice add or removes item from an array
- https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/splice.js
- sort return the new array by alphabetical order
- example: https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/sort.js
- reverse an array
- example: https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/reverse.js
- creates string from the item of the array
- https://github.com/coderMojnu/90DaysChallenge/blob/master/Day5/arrayAndFunction-day5/toString.js
Comments
Post a Comment