This file contains 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
# Fibonacci series using mem cache for effiecient solution | |
# Author: Jamal Uddin | |
# Date: 29.01.2018 | |
def fib(n, _cache={}): | |
if n in _cache: | |
return _cache[n] | |
elif n > 1: | |
return _cache.setdefault(n, fib(n - 1) + fib(n - 2)) | |
return n |
This file contains 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
// Price for groceries | |
var potatoPrice = 20; | |
var tomatoPrice = 30; | |
var fishPrice = 160; |
This file contains 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
// Price for groceries | |
var potatoPrice = 20; | |
var tomatoPrice = 30; | |
var fishPrice = 160; | |
// Output | |
console.log(potatoPrice); // Output should be: 20 | |
console.log(tomatoPrice); // Output should be: 30 | |
console.log(fishPrice); // Output should be: 160 |
This file contains 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
// Previuos groceries prices | |
var potatoPrice = 20; | |
var tomatoPrice = 30; | |
var fishPrice = 160; | |
console.log(potatoPrice); //should be present: 20 | |
// If we want to change potato price | |
potatoPrice = 25; | |
console.log(potatoPrice); //should be present: 25 |
This file contains 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
let mango; // Declaration or Initialization | |
mango = "We are mango people"; // String type data asisgned in mango variable | |
// Or you can declare or initialize and assign value all in onec. | |
let myNumber = 32; | |
let myString = 'Hello, World!'; | |
let myBoolean = true; | |
// If you want to see the output | |
console.log(mango); // We are mango people |
This file contains 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
// const type variable declaration | |
const PI = 3.14; // Global value of pi | |
const TAX_RATE = 8.5; // maybe your tax rate 8.5% | |
const INTEREST_RATE = 12; // Bank interest rate is 12% | |
// output | |
console.log(PI); // 3.14 | |
console.log(TAX_RATE); // 8.5 | |
console.log(INTEREST_RATE); // 12 |
This file contains 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
// Global scope | |
var num = 5; | |
function globalVar() { | |
console.log(num); // num = 5 | |
num = 8; | |
console.log(num); // num = 8 | |
} | |
console.log(num); // num = 5 |
This file contains 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
let id = function() { | |
const num = 10; | |
console.log(num); // output: 10 | |
}; | |
console.log(id()); // 10 | |
console.log(num); // ReferenceError: num is not defined |
This file contains 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
var singleQuotes = 'This is a string in single quotes.'; | |
var doubleQuotes = "This is a string in double quotes."; | |
let txtOne = "I'm from Dhaka, Bangladesh"; // I'm from Dhaka, Bangladesh | |
let txtTwo = 'I'm a programmer'; // SyntaxError: Unexpected identifier | |
// If you want to pass this Error let's do this way | |
let txtTwo = 'I\'m a programmer'; | |
console.log(txtTwo); // I'm a programmer |
This file contains 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
var num1 = 30; | |
var num2 = 5 / 0; // will return Infinity | |
var num3 = -5 / 0; // will return -Infinity | |
let x = 20 / "Shark"; // Will return NaN | |
const PI = 3.14; | |
console.log(num1); // Output: 30 | |
console.log(num2); // Output: Infinity | |
console.log(num3); // Output: -Infinity | |
console.log(x); // Output: NaN |
OlderNewer