Created
July 5, 2020 03:02
-
-
Save karkranikhil/cb6628900cf4eb84f4d55a5dbc17e9bd to your computer and use it in GitHub Desktop.
Salesforce JavaScript Developer 1 certification series
This file contains hidden or 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
| // The console.log() is a function that writes a message to log on the debugging console | |
| // Names can contain letters, digits, underscores, and dollar signs. | |
| // No limit o the length of the variable name | |
| // Names can begin with letter, $ and _ | |
| // Reserved words(like switch, if else) cannot be used as names | |
| // console.log(null+'10'); | |
| // var name = "Nikhil" | |
| // var age = 23 | |
| // var isAvailable =true | |
| // var variable="true" | |
| // var _name = "Nikhil" | |
| // var nullish = null | |
| // console.log("testing", name); | |
| // /// | |
| // name = "nikhil" | |
| // var name | |
| /**********Data Types*********** */ | |
| // There are 8 basic data types in JavaScript. | |
| // number Its for numbers of any kind: integer or floating - point, integers are limited by ±(2 ^ 53 - 1). | |
| // string for strings.A string may have zero or more characters, there’s no separate single - character type. | |
| // boolean for true / false. | |
| // null for unknown values – a standalone type that has a single value null. | |
| // undefined for unassigned values – a standalone type that has a single value undefined. | |
| // object for more complex data structures. | |
| // symbol for unique identifiers. | |
| // bigint its for integer numbers of arbitrary length. | |
| //type of operator | |
| // The typeof operator is used to get the data type of its operand. | |
| // it always returns a string of the data type. | |
| // The operand can be either a literal or a data structure such as a variable, a function, or an object.The operator returns the data type. | |
| /**Number Datatypes */ | |
| var num = 123 | |
| var num = 34.787 | |
| var num = -123 | |
| var num = -0 | |
| var num = 0 | |
| var num = Infinity | |
| var num = NaN | |
| //number respresents both integer and floating point | |
| /**String Datatypes */ | |
| // Anything in between double and single quote is String | |
| var first = "Hello" | |
| var last = 'World' | |
| var name = first + ' ' + last // Hello World | |
| var emptyString = '' | |
| var fullname = `nikhil karkra` | |
| var numString = '1' | |
| var booleanString = 'true' | |
| /*special string case**/ | |
| console.log(typeof (typeof 1)) | |
| console.log(typeof "true") | |
| /***Boolean Datatype */ | |
| var isValid = true | |
| var isInvalid = false | |
| /**bigInt datatype**/ | |
| //BigInt is a special numeric type that provides support for integers of arbitrary length. | |
| // BigInt is created by appending n to the end. | |
| var bigValue = 12345678910n | |
| var bigValue1 = BigInt(10) // 10n | |
| typeof bigValue | |
| /***Undefined */ | |
| //Undefined is the values that is not assigned | |
| var something // If a variable is declared, but not assigned JS automatically intialized it with undefined | |
| console.log(something) | |
| typeof something | |
| /*** Null ***/ | |
| // It's a special data type which represent "nothing" or "empty" or "value unknown" | |
| var nullVariable = null | |
| /***Object ***/ | |
| //In JS their are 7 primitive datatype because there value contains only single thing | |
| // Most complex data type is Object | |
| // JavaScript objects are containers for named values called properties or methods. | |
| // Three ways to create object | |
| // 1) Object literal | |
| var x = {} | |
| var detail = { | |
| name: "nikhil" | |
| } | |
| console.log(detail) | |
| //2) Object constructor | |
| var x = new Object() | |
| x.name = "nikhil" | |
| console.log(x) | |
| //3) Object.create() | |
| var obj = { | |
| name: "nikhil" | |
| } | |
| var newObj = Object.create(obj) | |
| //Key points | |
| // You can access the object properties using dot and array notation | |
| // array notation is useful when you have a space in you property name | |
| // use delete operator to delete the property or method | |
| var data = { "full name": "Nikhil Karkra", name: "nik" } | |
| delete data.name | |
| /**Symbol datatype**/ | |
| // ES6 introduces a new primitive type for JavaScript: Symbols. It gets created using the factory function Symbol() | |
| //Each time the Symbol() function is called, a new unique symbol is returned. | |
| var symbol = Symbol() | |
| var symbolWithDecription = Symbol("description") | |
| var foo = Symbol('baz'); | |
| var bar = Symbol('baz'); | |
| foo === bar | |
| // use case | |
| // By specification, object property keys may be either of string type, or of symbol type. Not numbers, not booleans, only strings or symbols, these two types. | |
| // In objects, symbol based keys never clash like strings | |
| // Key with symbol won't be enumerated in for...in loop, ignored by Object.keys() and JSON.stringify() | |
| var user = {}; | |
| var email = Symbol(); | |
| user.name = 'Nik'; | |
| user.age = 10; | |
| user[email] = '[email protected]'; | |
| Object.keys(user); | |
| // <-- Array [ "name", "age" ] | |
| Object.getOwnPropertyNames(user); | |
| // <-- Array [ "name", "age" ] | |
| JSON.stringify(user); | |
| /****Typesof */ | |
| // number | |
| typeof 23 | |
| typeof 23.783 | |
| typeof Infinity | |
| typeof NaN | |
| typeof 0 | |
| typeof -23 | |
| // String | |
| typeof '' | |
| typeof `hey` | |
| typeof 'hello' | |
| /** Boolean */ | |
| typeof true | |
| typeof false | |
| typeof "true" // "string" ? | |
| /**Undefined */ | |
| var x | |
| typeof x | |
| /**Symbol */ | |
| typeof Symbol() | |
| /**null **/ | |
| typeof null // "object"? | |
| //This is a bug and one that unfortunately can't be fixed, because it would break existing code. | |
| /** Object */ | |
| typeof {} // "object" | |
| //tricky typeof | |
| typeof (typeof 1) // "string" ? | |
| typeof !!(1) // "boolean" ? logical NOT is equivalent to boolean | |
| typeof function () { } //"function" | |
| typeof new Date() //"object" | |
| typeof [] // object | |
| /**************************Type Coercion ************************ */ | |
| //Explicitly(string, Number, Boolean) | |
| String(23) | |
| String(undefined) | |
| String(null) | |
| String("23") | |
| String(true) | |
| Number(23) | |
| Number("23") | |
| Number(undefined) | |
| Number("hello") | |
| //tricky explicit operation | |
| Number(null) | |
| Number(true) | |
| Number(false) | |
| Number("hello") | |
| Number([]) | |
| Number([33]) | |
| Number([33, 33]) | |
| Boolean(2) | |
| Boolean("2") | |
| Boolean(false) | |
| Boolean(0) | |
| Boolean('') | |
| Boolean('') //white space | |
| Boolean(NaN) | |
| Boolean(null) | |
| //Implicit Conversion | |
| //Internally + do Number() but if anyof thevalue is string it do Concat operation | |
| "Hello" + "World" | |
| + "16546542" | |
| 100 + "world" | |
| 100 + null + 20 + "world" | |
| true + 1 + "hey" | |
| undefined + 2 | |
| 100 + 200 + undefined + "hey" | |
| var x = {} | |
| x + 'hey' | |
| /**************************Equality comparisons ************************ */ | |
| 100 == "100" | |
| 100 === "100" | |
| true == 1 | |
| NaN === NaN | |
| - 0 === 0 | |
| //[] === [] false refrence is different | |
| var x = [] | |
| var y = x | |
| x === y | |
| // Strict comparison fails in few scenario | |
| Object.is(100, "100") | |
| Object.is(100, "100") | |
| /********Operators */ | |
| //Arithmetic operator | |
| //post increment | |
| var x = 10 | |
| console.log(x++) | |
| var y = 10 | |
| console.log(++y) | |
| // COmparision operator | |
| 3 > 2 | |
| 2 < 3 | |
| "hello" > "Hello" // "h"charCodeAt() | |
| // https://theasciicode.com.ar/ | |
| //logical operator Boolean coercion | |
| [] || "hey" | |
| 0 || "nik" | |
| 0 && 'nik' | |
| if (0 && 'nik') console.log("hey") | |
| !0 // !Boolean(0) | |
| !"hey" | |
| //Assignment Operators | |
| var x = 10 | |
| x += 20 // x=x+20 | |
| //Ternary operator | |
| var name = "nik" | |
| var isAvailable = name === "nik" ? "present" : "absent" | |
| //Conditions | |
| var value = 0 | |
| if (value) { | |
| console.log("success") | |
| } | |
| var name = "nik" | |
| if (name === "nik") { | |
| console.log("success") | |
| } else { | |
| console.log("failed") | |
| } | |
| var letter = "A" | |
| if (lettter === "A") { | |
| console.log("Apple") | |
| } else if (letter === "B") { | |
| console.log("Banana") | |
| } else { | |
| console.log("No idea") | |
| } | |
| //switch | |
| //= "1", 1 strict comparision | |
| var day = 1 | |
| var text1 = null | |
| switch (day) { | |
| case 0: | |
| text1 = "Today is Saturday"; | |
| break; | |
| case 1: | |
| text1 = "Today is Sunday"; | |
| break; | |
| default: | |
| text1 = "Looking forward to the Weekend"; | |
| } | |
| /***Var vs let vs const */ | |
| console.log(x) | |
| var x = 10 | |
| let name = "nik" | |
| let name = "salesforce" // can't be redeclared | |
| // blocked scope | |
| if (true) { | |
| let z2 = 10 | |
| } | |
| console.log(z2) | |
| /**String interpolation */ | |
| var name = "Salesforce ohana" | |
| console.log(`hello, ${name}`) | |
| console.log(`total, ${2 + 3}`) | |
| console.log(`Today's Date is, ${new Date().toDateString()}`) | |
| /***String Methods */ | |
| var str = "Hello Everyone" | |
| str.toLowerCase() // no mutation | |
| str.toUpperCase() | |
| var str = " Hello salesforce guys " | |
| str.trim() | |
| str.trimStart() | |
| str.trimEnd() | |
| // string.substring(start, end) // start index and end is not included | |
| var str = "Hello Everyone" | |
| str.substring(6) | |
| str.substring(6, 14) | |
| // if start is small and end is big it auto swap it | |
| str.substring(14, 6) | |
| // substr(start, length) | |
| var str = "Hello world!"; | |
| var res = str.substr(1, 4); | |
| var str = "Hello world!"; | |
| str.indexOf("world") | |
| str.replace("world", "salesforce") | |
| str.includes("world") | |
| //convert string to array | |
| // string.split(separator, limit) | |
| var str = "Hello Everyone"; | |
| str.split('') | |
| str.split('', 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment