Showing posts from March, 2019

JavaScript - number

// there are no separate types for integers and floating points numbers in JS // only one type for both is used i.e. 'number' // when you assign some variable or constant a number, its type become number let num1 = 10; console.log('value of num1 = ' + num1); console.log('typoe of num1 = ' + typeof num1); // though above used syntax is more common, but we can create // a number type variable using Number function too. like below: // below syntax is useful when you want to create 'number' variable // from string or others. we can pass that to Number function. let num2 = Number(20); console.log('num2 = ' + num2); // we can call this method passing string and other types too // in case of other types, its string equivalent would be used // to create number. num2 = Number("30"); console.log('now value of num2 = ' + num2); // like string, primitive type 'number' has also a corresponding // wrapper reference type i.e.

JavaScript - string

console.log("// ----------------- Strings ----------------------"); console.log("///////////////////////////////////////////////////"); // 1. declaration and assignment // 2. string literals. defining single line and multi-line string literals // 3. functions: length, toLowerCase, toUpperCase, substring, trim, concat, indexOf, lastIndexOf, charAt // 4. using string as array - for reading. since ES5 // 5. comparing strings // 6. primitive string and String object. How to create each? use typeof to see, what is difference. what to prefer. // 7. auto-boxing: Automatic conversion of primitive to String object depending on context // 8. primitive is pointer to a row memory location i.e. fast speed/random-access // 9. they are not same e.g. eval method takes expression in primitive string // 10. use instance and typeof to check each case // 11. converting one form to another. e.g. new keyword and valueof method lastName = "Shahzad"; console.log(lastName); co