[Index] [Catalog] [Bottom] R: 29 / P: 12 / Connecting

File: ClipboardImage.png (892.9KB, 3840x2160)
Post Image
i will learn javascript, i don't know anything about it as I always codes in c/c++. but today is the day I must decend, so that I can get a job. starting with variables, wot the actual fuck broosssss. it's even worse than python. there are 3 diff ways of initializing variables, that are var, let, and const. why 3, const is understandable, but var and let????? is this how you webjeet codes in???? and what's up with this comparison operators??? "==="??? why not just "==" i'm already loosing my mind. i hope typescript may have fixed all these bullshits
>>1011 Its not that hard once you get hand to it. No-one use var now a days. Ans yes, i only know js well now as i put more effort in this .
okay so here is a plan, i will go through mdn, and i continue to learn, i will share all my learning here so that I don't loose my motivation of learning this language.
one more interesting thing is unlike other language that has 2 types for numbers, one int and other is float. jabhascript doesn't have any of those. instead it has one type call "Number" that includes everything including decimal, whole num, and integers
undefined is not undeclared. undefined is a premitive types where the values if absent. for instances let fuckoff; console.log(fuckoff) // this will be undefined console.log(fuckoffhundredtimes) // this is undeclared. also one thing more i noticed is that upon running that code with "fuckoffhunderdtimes" it gives me error says "not defined". it's the worst part. like dude how would i know if i declared it or not
now null and undefined are 2 diff thing. undefined: it doesn't exist at all null: it kind of exist, but it's empty. what is this faggotary yaara. i'm hating this ex- // undefined example let myName; console.log(myName); // null example let myName = null; console.log(myName);
since it's very weakly typed. worst than python btw. so if i do something like below let num = 2; let sNum = "2"; console.log(num + sNum); it will give me the output "22" instead of error.
The .length property is used to get the number of characters in a string.
>>1011 U should start with typescript, it will make more sense than javascript Typescript is same as javascript but with its type check and other things being implemented
>>1020 umm, if i'm not wrong typescript is essentially js with types enforce right?
>>1020 https://developer.mozilla.org/en-US/docs/Glossary/Truthyhttps://developer.mozilla.org/en-US/docs/Glossary/Truthy okay so truthy and falsy are kind of weird, you don't have to convert the value or say express the values in boolean form before passing it to the if statement. if ("hello") // this is truthy if (5) // this is also truthy if (!0) // this falsy if (!null) // this is falsy
>>1024 https://developer.mozilla.org/en-US/docs/Glossary/Falsyhttps://developer.mozilla.org/en-US/docs/Glossary/Falsy
File: ClipboardImage.png (40.3KB, 771x345)
Post Image
nullish coalescing operator `??` is a way to handle cases where a variable might be null or undefined. let myName = null; console.log(myName ?? "anon"); // here if myName is null then it logs the "anon" and vices-versa
global scope in js can be access from anywhere, also for browser or frontend related shit global can be access from window like window.myGlobalBullshit = "something" while in node.js, we can access global with global like `global.myGlobalVar = "bullshit";`
huh... pass by value kind of work similar to python as in javascript. the exception is for obj and arrays.
immediate invocation invoke function right after defining it using iife (https://developer.mozilla.org/en-US/docs/Glossary/IIFE)https://developer.mozilla.org/en-US/docs/Glossary/IIFE) (function () { console.log("some bullshit"); })();
i think i'm liking it a bit.
javascript objects are often used to store key-value pairs. const apple = { name: "apple", radius: 2, color: "red" }; we can access the value like following console.log(apple.name); console.log(apple.color); console.log(apple.radius);
optional chaining helps in minimizing the error for fields that aren't present in obj. // optional chaining const tournament = { prize: { units: "dollar", value: 100, }, }; // if i don't include that ?, then it will throw an error const h = tournament.referee?.height; console.log(h);
>>1033 i must use chain when I expect an object may not exist
so apparently you can use method in objects too // objects methods const person = { firstName: "fuck", lastName: "you", getFullName() { return this.firstName + " " + this.lastName; }, }; console.log(person.getFullName()); god damn it, i hope no one saw my real name
just so you know, javascript const only stops you from reassigning the variable. you can still change it's properties. // methods mutate const tree = { height: 256, color: "green", cut() { this.height /= 2; }, }; tree.cut(); console.log(tree.height); tree.cut(); console.log(tree.height);
function add(a, b) { return a + b; } console.log(add(1, 1)); const arrowFunction = (a, b) => { return a + b; }; console.log(arrowFunction(1, 1)); // arrow functions/method in obj will always refers to the parent of the obj for `this` keyword
// spread syntax will copy and combine multiple objects, if properties were of same // name, the engine or node will select the right most properties name function mergeTwoTemplates(defaultTemplates, customTemplates) { const allTemplates = { ...defaultTemplates, ...customTemplates }; return allTemplates; } const defaultTemplates = { name: "something", cost: 122, }; const customTemplates = { preview: "something", cost: 123, }; const resultTemplate = mergeTwoTemplates(defaultTemplates, customTemplates); console.log(resultTemplate);
I have been gone for too long, but apparently i'm back. huh, javascript eventloop is pretty interesting thing.
https://www.youtube.com/watch?v=8aGhZQkoFbQ
https://www.youtube.com/watch?v=8aGhZQkoFbQ
so javascript is actually a very good choice for asynchronous programming. the main tread runs on single-tread, the async process is non-blocking, it will run in background while running the main thread (kinda like concurrently)
there are mainly 3 important parts in js runtime. - call stack - task queue - microtask queue call stack as the name suggest is a stack of "functions" task queue and microtask queue are FIFO structure that holds callbacks from async operation like setTimout, fetch, setInterval I/O bla bla bla. then only difference between task queue and microtask queue is priority. task queue has more priority that microtask queue
File: ClipboardImage.png (369.4KB, 3840x3840)
Post Image
now that i have some good hold on js, i think I can start typescript (which is as some people says is just a linter)
>>1097 Dont
>>1100 it's industry standard, why not?

[Post Reply]
[Index] [Catalog] [Top] R: 29 / P: 12 / Connecting

Theme: