Skip to content

Instantly share code, notes, and snippets.

View khanh96le's full-sized avatar

Khanh Quoc Le khanh96le

  • Hanoi, VietNam
View GitHub Profile

hihi

var i = 0;
function hello(){
  console.log("hello wolrd")
}

#Values, Types, and Operator in JavaScript There are 6 basic types of value: number, string, Boolean, obeject, function, and undefined value

// NUMBER
console.log(2.99e9); 
// -> 2990000000 (2.99e9 = 2.99 x 10^9)
console.log(typeof NaN);
console.log(0 /0);
console.log(typeof Infinity);
console.log(1 /0);

#What the different between 3 functions below?

function Test(x) {
    console.log(x);
    var x = 10;
    console.log(x);    
}

function TestP(x) {
 return new Promise(function(fulfill, reject){

// What is an expression? // --> a fragment of code that produces a value is calls an expression

VARIABLE:
var ten = 10;
console.log(ten * ten);

var mood = "light";
console.log(mood);
mood = "dark";

#Function in Javascrpit ##1.Defining a Function

var square = function(x) {
  return x * x;
};
square(5);

##2. Scope

#Object and Array in JavaScript

Data Sets

// Data Sets
var listOfNumbers = [2,3,5,7,11];
console.log(listOfNumbers[1]);
console.log(listOfNumbers[1-1]);

##Properties and Methods

#Higher-Order Functions ##Abstraction

// What version is easy to understand, and what version is more bugs
// version 1
var total = 0, count = 1;
while (count <= 10) {
    total += count;
    count += 1;
}

#The Scret Life of Objects (Object-Oriented Programming)

// // Method
// // method is simply property that hold function values
// var rabbit = {};
// rabbit.speak = function(line){
//     console.log("The rabit says:'" + line + "'");
// };
// rabbit.speak("I'm alive");

In javascript bugs may be displayed is NaN or underfined and program still run but after that, the wrong value can cause some mistake when we use it So, finding bugs and fix them is the quiet hard work in javascript But we can do, and this job is called debugging

##STRICT MODE This is the way to find errors that javascript ignores. Example is using an undefined variable. if we dont use strick mode, then everything will be ok, but if using, the error will be shown

function SpotProblem(){
//     "use strict";
 for (counter = 0; counter &lt; 10; counter++){

#Regular Expression in JavaScript This lab is based on Chapter9: EloquentJavaScript ##Creating a regular expression There are 2 ways:

var re1 = new RegExp("abc");
var re2 = /abc/

there are some special characters such as question mark, or plus sign. If you want to use them, you have to use backslash. Like this: