salesforce javascript developer 1 - variable types, scope

listening to louis rossmann on October 14th, 2021

I noticed a new certification offered by Salesforce, Javascript Developer 1. Maybe it's not new, but first time I have seen it. I'm making my notes based on the Study for the Salesforce JavaScript Developer I Exam Trail. These notes are much better than my last SF post. I'll have to go back and update that at some point. If you have a good understanding of javascript, this should be cake for you.


variable - points to storage location, must begin with a letter, underscore, or dollah sign, e.g. testVariable, _anotherOne, $container

It is case-sensitive.


8 data types

  • boolean - true or false
  • number - integer or floating point
  • string - text value
  • symbol - unique and immutable values
  • object - key/pair values (think JSON)
  • null
  • bigInt - big ass number lel
  • undefined - not defined lel

NOTE: we don't need to assign a data type when declaring a variable (js is considered a dynamic and loosely typed language)

The exception is const. You must have data assigned, it doesn't return "undefined", it says "missing identifier"


Global and local scope


Global variables are accessible in multiple functions.

js
var name = "jen"
function myName() {
nickName();
console.log(`my name is ${name}`);
}
function nickName() {
name = "jennay"
}
myName();
// console.log will output:
// "my name is jennay"

Local variables can only be accessed in the function in which they are declared.

js
var name = "jen"
function myName() {
nickName();
console.log(`my name is ${name}`);
}
function nickName() {
//the var in front of the variable makes this a local variable, the scope has changed.
var name = "jennay"
}

Hoisting


Hoisting allows accessing a variable before its defined, but returns a val of undefined

Note: strict mode can be used to avoid hoisting

js
function myName() {
nickName();
console.log(`my name is ${name}`);
}
myName();
var name;
// it's available but it is undefined
// BUT IF YOU USE let INSTEAD OF var
// console.log error
// cannot access 'name' before initialization

Typecasting


Variable of one data type can be explicitly converted to another data type.

  • Number()
  • String()
  • Boolean()
  • toString()
  • parseInt()
  • parseFloat()
js
// hotdogs is a string
let hotdogs = "42";
// now it's a number
Number(hotdogs); // returns 42

null vs undefined

Two primitive data types that cannot contain values

Undefined is assigned by javascript engine

Null is assigned by developer


©2022 Jennifer Quispe. All rights reserved.

Privacy Policy