---
# System prepended metadata

title: 2704. To Be Or Not To Be
tags: [JavaScript]

---

# [2704. To Be Or Not To Be](https://leetcode.com/problems/to-be-or-not-to-be/description/?envType=study-plan-v2&envId=30-days-of-javascript)
![image](https://hackmd.io/_uploads/BkU4YXnER.png)
題目要求我們寫兩個function
一個tobe nottobe
並且在個別達成時return false時throw
但由於throw是直敘式 沒辦法回傳固定文字
所以我們寫一個func來接他並回傳
```js=
const expect = (val) =>{
    throwErr = (str)=>{
      throw new Error(str);
    }
    toBe = (val2) =>{
    return val === val2? true : throwErr("Not Equal") ;
    }
    notToBe = (val2) =>{
    return val !== val2? true : throwErr("Equal") ; 
    }
return {toBe,notToBe};

};
```